diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-06 21:39:29 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-11-06 15:39:29 +0200 |
commit | 12170d26a7fc75beef46311996db3798d7ad7c1c (patch) | |
tree | 92ee2787541ef99680fd9825dda04552930de4df /models/issue_comment.go | |
parent | 72aa5a20ecf8aa3f7c110fd51c37994d950e0ba8 (diff) | |
download | gitea-12170d26a7fc75beef46311996db3798d7ad7c1c.tar.gz gitea-12170d26a7fc75beef46311996db3798d7ad7c1c.zip |
Split sendCreateCommentAction as two parts, one for update comment related informations, another for actions (#8784)
* Split sendCreateCommentAction as two parts, one for update comment related informations, another for actions
* fix lint
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r-- | models/issue_comment.go | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go index 90bb8c53ac..63f5f6b778 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -535,6 +535,10 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err return nil, err } + if err = updateCommentInfos(e, opts, comment); err != nil { + return nil, err + } + if err = sendCreateCommentAction(e, opts, comment); err != nil { return nil, err } @@ -546,19 +550,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err return comment, nil } -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, - } +func updateCommentInfos(e *xorm.Session, opts *CreateCommentOptions, comment *Comment) (err error) { // Check comment type. switch opts.Type { case CommentTypeCode: @@ -574,8 +566,6 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen } fallthrough case CommentTypeComment: - act.OpType = ActionCommentIssue - if _, err = e.Exec("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil { return err } @@ -601,30 +591,54 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err) } } + case CommentTypeReopen, CommentTypeClose: + if err = opts.Issue.updateClosedNum(e); err != nil { + return err + } + } + // update the issue's updated_unix column + 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 } - - if err = opts.Issue.updateClosedNum(e); err != nil { - return err - } - case CommentTypeClose: act.OpType = ActionCloseIssue if opts.Issue.IsPull { act.OpType = ActionClosePullRequest } - - if err = opts.Issue.updateClosedNum(e); err != nil { - return err - } - } - // update the issue's updated_unix column - if err = updateIssueCols(e, opts.Issue, "updated_unix"); err != nil { - return err } // Notify watchers for whatever action comes in, ignore if no action type. if act.OpType > 0 { |