aboutsummaryrefslogtreecommitdiffstats
path: root/modules/notification
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-11-14 10:57:36 +0800
committerGitHub <noreply@github.com>2019-11-14 10:57:36 +0800
commitdad67cae5455f346f122ab26ec50ac4e029cacf4 (patch)
treee16407c08bb1c5ca07b9f3601e55e2c13eb79ac8 /modules/notification
parent16a43156a85710fd01fc7d8e5092fb82371fa271 (diff)
downloadgitea-dad67cae5455f346f122ab26ec50ac4e029cacf4.tar.gz
gitea-dad67cae5455f346f122ab26ec50ac4e029cacf4.zip
Refactor pull request review (#8954)
* refactor submit review * remove unnecessary code * remove unused comment * fix lint * remove duplicated actions * remove duplicated actions * fix typo * fix comment content
Diffstat (limited to 'modules/notification')
-rw-r--r--modules/notification/action/action.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go
index d481bd8c4d..36035b864f 100644
--- a/modules/notification/action/action.go
+++ b/modules/notification/action/action.go
@@ -6,6 +6,7 @@ package action
import (
"fmt"
+ "strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
@@ -117,3 +118,51 @@ func (a *actionNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *
log.Error("notify watchers '%d/%d': %v", doer.ID, repo.ID, err)
}
}
+
+func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) {
+ if err := review.LoadReviewer(); err != nil {
+ log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err)
+ return
+ }
+ if err := review.LoadCodeComments(); err != nil {
+ log.Error("LoadCodeComments '%d/%d': %v", review.Reviewer.ID, review.ID, err)
+ return
+ }
+
+ var actions = make([]*models.Action, 0, 10)
+ for _, lines := range review.CodeComments {
+ for _, comments := range lines {
+ for _, comm := range comments {
+ actions = append(actions, &models.Action{
+ ActUserID: review.Reviewer.ID,
+ ActUser: review.Reviewer,
+ Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comm.Content, "\n")[0]),
+ OpType: models.ActionCommentIssue,
+ RepoID: review.Issue.RepoID,
+ Repo: review.Issue.Repo,
+ IsPrivate: review.Issue.Repo.IsPrivate,
+ Comment: comm,
+ CommentID: comm.ID,
+ })
+ }
+ }
+ }
+
+ if strings.TrimSpace(comment.Content) != "" {
+ actions = append(actions, &models.Action{
+ ActUserID: review.Reviewer.ID,
+ ActUser: review.Reviewer,
+ Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comment.Content, "\n")[0]),
+ OpType: models.ActionCommentIssue,
+ RepoID: review.Issue.RepoID,
+ Repo: review.Issue.Repo,
+ IsPrivate: review.Issue.Repo.IsPrivate,
+ Comment: comment,
+ CommentID: comment.ID,
+ })
+ }
+
+ if err := models.NotifyWatchersActions(actions); err != nil {
+ log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)
+ }
+}