remove unused method and rename createcommentWithNoAction (#9367)

This commit is contained in:
Lunny Xiao 2019-12-16 11:54:24 +08:00 committed by GitHub
parent 67b316a954
commit 43ada65571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 17 additions and 89 deletions

View File

@ -664,7 +664,7 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (*C
cmtType = CommentTypeReopen cmtType = CommentTypeReopen
} }
return createCommentWithNoAction(e, &CreateCommentOptions{ return createComment(e, &CreateCommentOptions{
Type: cmtType, Type: cmtType,
Doer: doer, Doer: doer,
Repo: issue.Repo, Repo: issue.Repo,
@ -724,7 +724,7 @@ func (issue *Issue) ChangeTitle(doer *User, oldTitle string) (err error) {
OldTitle: oldTitle, OldTitle: oldTitle,
NewTitle: issue.Title, NewTitle: issue.Title,
} }
if _, err = createCommentWithNoAction(sess, opts); err != nil { if _, err = createComment(sess, opts); err != nil {
return fmt.Errorf("createComment: %v", err) return fmt.Errorf("createComment: %v", err)
} }
if err = issue.addCrossReferences(sess, doer, true); err != nil { if err = issue.addCrossReferences(sess, doer, true); err != nil {
@ -752,7 +752,7 @@ func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branc
Issue: issue, Issue: issue,
CommitSHA: branchName, CommitSHA: branchName,
} }
if _, err = createCommentWithNoAction(sess, opts); err != nil { if _, err = createComment(sess, opts); err != nil {
return err return err
} }
@ -894,7 +894,7 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
OldMilestoneID: 0, OldMilestoneID: 0,
MilestoneID: opts.Issue.MilestoneID, MilestoneID: opts.Issue.MilestoneID,
} }
if _, err = createCommentWithNoAction(e, opts); err != nil { if _, err = createComment(e, opts); err != nil {
return err return err
} }
} }

View File

@ -140,7 +140,7 @@ func (issue *Issue) toggleAssignee(sess *xorm.Session, doer *User, assigneeID in
AssigneeID: assigneeID, AssigneeID: assigneeID,
} }
// Comment // Comment
comment, err = createCommentWithNoAction(sess, opts) comment, err = createComment(sess, opts)
if err != nil { if err != nil {
return false, nil, fmt.Errorf("createComment: %v", err) return false, nil, fmt.Errorf("createComment: %v", err)
} }

View File

@ -495,7 +495,7 @@ func (c *Comment) CodeCommentURL() string {
return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag()) return fmt.Sprintf("%s/files#%s", c.Issue.HTMLURL(), c.HashTag())
} }
func createCommentWithNoAction(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) { func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) {
var LabelID int64 var LabelID int64
if opts.Label != nil { if opts.Label != nil {
LabelID = opts.Label.ID LabelID = opts.Label.ID
@ -589,55 +589,6 @@ func updateCommentInfos(e *xorm.Session, opts *CreateCommentOptions, comment *Co
return updateIssueCols(e, opts.Issue, "updated_unix") return updateIssueCols(e, opts.Issue, "updated_unix")
} }
func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, comment *Comment) (err error) {
// Compose comment action, could be plain comment, close or reopen issue/pull request.
// This object will be used to notify watchers in the end of function.
act := &Action{
ActUserID: opts.Doer.ID,
ActUser: opts.Doer,
Content: fmt.Sprintf("%d|%s", opts.Issue.Index, strings.Split(opts.Content, "\n")[0]),
RepoID: opts.Repo.ID,
Repo: opts.Repo,
Comment: comment,
CommentID: comment.ID,
IsPrivate: opts.Repo.IsPrivate,
}
// Check comment type.
switch opts.Type {
case CommentTypeCode:
if comment.ReviewID != 0 {
if comment.Review == nil {
if err := comment.loadReview(e); err != nil {
return err
}
}
if comment.Review.Type <= ReviewTypePending {
return nil
}
}
fallthrough
case CommentTypeComment:
act.OpType = ActionCommentIssue
case CommentTypeReopen:
act.OpType = ActionReopenIssue
if opts.Issue.IsPull {
act.OpType = ActionReopenPullRequest
}
case CommentTypeClose:
act.OpType = ActionCloseIssue
if opts.Issue.IsPull {
act.OpType = ActionClosePullRequest
}
}
// Notify watchers for whatever action comes in, ignore if no action type.
if act.OpType > 0 {
if err = notifyWatchers(e, act); err != nil {
log.Error("notifyWatchers: %v", err)
}
}
return nil
}
func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) { func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
var content string var content string
var commentType CommentType var commentType CommentType
@ -667,7 +618,7 @@ func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlin
Issue: issue, Issue: issue,
Content: content, Content: content,
} }
comment, err := createCommentWithNoAction(e, opts) comment, err := createComment(e, opts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -692,7 +643,7 @@ func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dep
Issue: issue, Issue: issue,
DependentIssueID: dependentIssue.ID, DependentIssueID: dependentIssue.ID,
} }
if _, err = createCommentWithNoAction(e, opts); err != nil { if _, err = createComment(e, opts); err != nil {
return return
} }
@ -703,7 +654,7 @@ func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dep
Issue: dependentIssue, Issue: dependentIssue,
DependentIssueID: issue.ID, DependentIssueID: issue.ID,
} }
_, err = createCommentWithNoAction(e, opts) _, err = createComment(e, opts)
return return
} }
@ -745,27 +696,7 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
return nil, err return nil, err
} }
comment, err = createCommentWithNoAction(sess, opts) comment, err = createComment(sess, opts)
if err != nil {
return nil, err
}
if err = sess.Commit(); err != nil {
return nil, err
}
return comment, nil
}
// CreateCommentWithNoAction creates comment of issue or commit with no action created
func CreateCommentWithNoAction(opts *CreateCommentOptions) (comment *Comment, err error) {
sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
comment, err = createCommentWithNoAction(sess, opts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -433,7 +433,7 @@ func newIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (err
Label: label, Label: label,
Content: "1", Content: "1",
} }
if _, err = createCommentWithNoAction(e, opts); err != nil { if _, err = createComment(e, opts); err != nil {
return err return err
} }
@ -509,7 +509,7 @@ func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (
Issue: issue, Issue: issue,
Label: label, Label: label,
} }
if _, err = createCommentWithNoAction(e, opts); err != nil { if _, err = createComment(e, opts); err != nil {
return err return err
} }

View File

@ -52,7 +52,7 @@ func updateIssueLock(opts *IssueLockOptions, lock bool) error {
Type: commentType, Type: commentType,
Content: opts.Reason, Content: opts.Reason,
} }
if _, err := createCommentWithNoAction(sess, opt); err != nil { if _, err := createComment(sess, opt); err != nil {
return err return err
} }

View File

@ -422,7 +422,7 @@ func changeMilestoneAssign(e *xorm.Session, doer *User, issue *Issue, oldMilesto
OldMilestoneID: oldMilestoneID, OldMilestoneID: oldMilestoneID,
MilestoneID: issue.MilestoneID, MilestoneID: issue.MilestoneID,
} }
if _, err := createCommentWithNoAction(e, opts); err != nil { if _, err := createComment(e, opts); err != nil {
return err return err
} }
} }

View File

@ -127,13 +127,10 @@ func (issue *Issue) createCrossReferences(e *xorm.Session, ctx *crossReferencesC
RefAction: xref.Action, RefAction: xref.Action,
RefIsPull: ctx.OrigIssue.IsPull, RefIsPull: ctx.OrigIssue.IsPull,
} }
comment, err := createCommentWithNoAction(e, opts) _, err := createComment(e, opts)
if err != nil { if err != nil {
return err return err
} }
if err = sendCreateCommentAction(e, opts, comment); err != nil {
return err
}
} }
return nil return nil
} }

View File

@ -324,7 +324,7 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content strin
} }
} }
comm, err := createCommentWithNoAction(sess, &CreateCommentOptions{ comm, err := createComment(sess, &CreateCommentOptions{
Type: CommentTypeReview, Type: CommentTypeReview,
Doer: doer, Doer: doer,
Content: review.Content, Content: review.Content,

View File

@ -144,7 +144,7 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
} }
patch = gitdiff.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines) patch = gitdiff.CutDiffAroundLine(patchBuf, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
} }
return models.CreateCommentWithNoAction(&models.CreateCommentOptions{ return models.CreateComment(&models.CreateCommentOptions{
Type: models.CommentTypeCode, Type: models.CommentTypeCode,
Doer: doer, Doer: doer,
Repo: repo, Repo: repo,