diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-12-16 05:57:34 +0800 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-12-15 16:57:34 -0500 |
commit | 67b316a954b161cac27e16b6455837881919dd94 (patch) | |
tree | 46e0278f556447cd9228d63c49a32dacea1f3352 /modules/notification/action | |
parent | c6b3c5bcefde6be4c64f5769a38962c2ce6ad6de (diff) | |
download | gitea-67b316a954b161cac27e16b6455837881919dd94.tar.gz gitea-67b316a954b161cac27e16b6455837881919dd94.zip |
Refactor comment (#9330)
* Refactor comment
* fix test
* improve code
Diffstat (limited to 'modules/notification/action')
-rw-r--r-- | modules/notification/action/action.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go index 9caeb5aac0..7441de638a 100644 --- a/modules/notification/action/action.go +++ b/modules/notification/action/action.go @@ -53,6 +53,60 @@ func (a *actionNotifier) NotifyNewIssue(issue *models.Issue) { } } +// NotifyIssueChangeStatus notifies close or reopen issue to notifiers +func (a *actionNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) { + // 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 := &models.Action{ + ActUserID: doer.ID, + ActUser: doer, + Content: fmt.Sprintf("%d|%s", issue.Index, ""), + RepoID: issue.Repo.ID, + Repo: issue.Repo, + Comment: actionComment, + CommentID: actionComment.ID, + IsPrivate: issue.Repo.IsPrivate, + } + // Check comment type. + if closeOrReopen { + act.OpType = models.ActionCloseIssue + if issue.IsPull { + act.OpType = models.ActionClosePullRequest + } + } else { + act.OpType = models.ActionReopenIssue + if issue.IsPull { + act.OpType = models.ActionReopenPullRequest + } + } + + // Notify watchers for whatever action comes in, ignore if no action type. + if err := models.NotifyWatchers(act); err != nil { + log.Error("NotifyWatchers: %v", err) + } +} + +// NotifyCreateIssueComment notifies comment on an issue to notifiers +func (a *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment) { + act := &models.Action{ + OpType: models.ActionCommentIssue, + ActUserID: doer.ID, + ActUser: doer, + Content: fmt.Sprintf("%d|%s", issue.Index, comment.Content), + RepoID: issue.Repo.ID, + Repo: issue.Repo, + Comment: comment, + CommentID: comment.ID, + IsPrivate: issue.Repo.IsPrivate, + } + + // Notify watchers for whatever action comes in, ignore if no action type. + if err := models.NotifyWatchers(act); err != nil { + log.Error("NotifyWatchers: %v", err) + } +} + func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest) { if err := pull.LoadIssue(); err != nil { log.Error("pull.LoadIssue: %v", err) |