}
// New action comment
- if _, err = createStatusComment(e, doer, issue); err != nil {
+ cmtType := CommentTypeClose
+ if !issue.IsClosed {
+ cmtType = CommentTypeReopen
+ }
+ if _, err := createComment(e, &CreateCommentOptions{
+ Type: cmtType,
+ Doer: doer,
+ Repo: issue.Repo,
+ Issue: issue,
+ }); err != nil {
return err
}
return fmt.Errorf("loadRepo: %v", err)
}
- if _, err = createChangeTitleComment(sess, doer, issue.Repo, issue, oldTitle, issue.Title); err != nil {
- return fmt.Errorf("createChangeTitleComment: %v", err)
+ if _, err = createComment(sess, &CreateCommentOptions{
+ Type: CommentTypeChangeTitle,
+ Doer: doer,
+ Repo: issue.Repo,
+ Issue: issue,
+ OldTitle: oldTitle,
+ NewTitle: issue.Title,
+ }); err != nil {
+ return fmt.Errorf("createComment: %v", err)
}
if err = issue.neuterCrossReferences(sess); err != nil {
if err := sess.Begin(); err != nil {
return err
}
- if _, err := createDeleteBranchComment(sess, doer, repo, issue, branchName); err != nil {
+ if _, err := createComment(sess, &CreateCommentOptions{
+ Type: CommentTypeDeleteBranch,
+ Doer: doer,
+ Repo: repo,
+ Issue: issue,
+ CommitSHA: branchName,
+ }); err != nil {
return err
}
}
// Comment
- comment, err = createAssigneeComment(sess, doer, issue.Repo, issue, assigneeID, removed)
+ comment, err = createComment(sess, &CreateCommentOptions{
+ Type: CommentTypeAssignees,
+ Doer: doer,
+ Repo: issue.Repo,
+ Issue: issue,
+ RemovedAssignee: removed,
+ AssigneeID: assigneeID,
+ })
if err != nil {
- return false, nil, fmt.Errorf("createAssigneeComment: %v", err)
+ return false, nil, fmt.Errorf("createComment: %v", err)
}
// if pull request is in the middle of creation - don't call webhook
return nil
}
-func createStatusComment(e *xorm.Session, doer *User, issue *Issue) (*Comment, error) {
- cmtType := CommentTypeClose
- if !issue.IsClosed {
- cmtType = CommentTypeReopen
- }
- return createComment(e, &CreateCommentOptions{
- Type: cmtType,
- Doer: doer,
- Repo: issue.Repo,
- Issue: issue,
- })
-}
-
-func createLabelComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, label *Label, add bool) (*Comment, error) {
- var content string
- if add {
- content = "1"
- }
- return createComment(e, &CreateCommentOptions{
- Type: CommentTypeLabel,
- Doer: doer,
- Repo: repo,
- Issue: issue,
- Label: label,
- Content: content,
- })
-}
-
func createMilestoneComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldMilestoneID, milestoneID int64) (*Comment, error) {
return createComment(e, &CreateCommentOptions{
Type: CommentTypeMilestone,
})
}
-func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, assigneeID int64, removedAssignee bool) (*Comment, error) {
- return createComment(e, &CreateCommentOptions{
- Type: CommentTypeAssignees,
- Doer: doer,
- Repo: repo,
- Issue: issue,
- RemovedAssignee: removedAssignee,
- AssigneeID: assigneeID,
- })
-}
-
func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
var content string
})
}
-func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldTitle, newTitle string) (*Comment, error) {
- return createComment(e, &CreateCommentOptions{
- Type: CommentTypeChangeTitle,
- Doer: doer,
- Repo: repo,
- Issue: issue,
- OldTitle: oldTitle,
- NewTitle: newTitle,
- })
-}
-
-func createDeleteBranchComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, branchName string) (*Comment, error) {
- return createComment(e, &CreateCommentOptions{
- Type: CommentTypeDeleteBranch,
- Doer: doer,
- Repo: repo,
- Issue: issue,
- CommitSHA: branchName,
- })
-}
-
// Creates issue dependency comment
func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dependentIssue *Issue, add bool) (err error) {
cType := CommentTypeAddDependency
return
}
- if _, err = createLabelComment(e, doer, issue.Repo, issue, label, true); err != nil {
+ if _, err = createComment(e, &CreateCommentOptions{
+ Type: CommentTypeLabel,
+ Doer: doer,
+ Repo: issue.Repo,
+ Issue: issue,
+ Label: label,
+ Content: "1",
+ }); err != nil {
return err
}
return
}
- if _, err = createLabelComment(e, doer, issue.Repo, issue, label, false); err != nil {
+ if _, err = createComment(e, &CreateCommentOptions{
+ Type: CommentTypeLabel,
+ Doer: doer,
+ Repo: issue.Repo,
+ Issue: issue,
+ Label: label,
+ }); err != nil {
return err
}
OrigComment *Comment
}
-func newCrossReference(e *xorm.Session, ctx *crossReferencesContext, xref *crossReference) error {
- var refCommentID int64
- if ctx.OrigComment != nil {
- refCommentID = ctx.OrigComment.ID
- }
- _, err := createComment(e, &CreateCommentOptions{
- Type: ctx.Type,
- Doer: ctx.Doer,
- Repo: xref.Issue.Repo,
- Issue: xref.Issue,
- RefRepoID: ctx.OrigIssue.RepoID,
- RefIssueID: ctx.OrigIssue.ID,
- RefCommentID: refCommentID,
- RefAction: xref.Action,
- RefIsPull: xref.Issue.IsPull,
- })
- return err
-}
-
func neuterCrossReferences(e Engine, issueID int64, commentID int64) error {
active := make([]*Comment, 0, 10)
sess := e.Where("`ref_action` IN (?, ?, ?)", references.XRefActionNone, references.XRefActionCloses, references.XRefActionReopens)
return err
}
for _, xref := range xreflist {
- if err = newCrossReference(e, ctx, xref); err != nil {
+ var refCommentID int64
+ if ctx.OrigComment != nil {
+ refCommentID = ctx.OrigComment.ID
+ }
+ if _, err := createComment(e, &CreateCommentOptions{
+ Type: ctx.Type,
+ Doer: ctx.Doer,
+ Repo: xref.Issue.Repo,
+ Issue: xref.Issue,
+ RefRepoID: ctx.OrigIssue.RepoID,
+ RefIssueID: ctx.OrigIssue.ID,
+ RefCommentID: refCommentID,
+ RefAction: xref.Action,
+ RefIsPull: xref.Issue.IsPull,
+ }); err != nil {
return err
}
}