From e6acce649b348cc497b999100a170866a90c87b8 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Sat, 2 Jan 2021 18:04:02 +0100 Subject: Send notifications for mentions in pulls, issues, (code-)comments (#14218) Fixes #14187: mention handling extracted from email notification code Fixes #14013: add notification for mentions in pull request code comments Fixes #13450: Not receiving any emails with setting "Only Email on Mention" --- services/pull/pull.go | 7 ++++++- services/pull/review.go | 27 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'services/pull') diff --git a/services/pull/pull.go b/services/pull/pull.go index 476c5dad54..35dcbf9604 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -53,7 +53,12 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6 return err } - notification.NotifyNewPullRequest(pr) + mentions, err := pull.FindAndUpdateIssueMentions(models.DefaultDBContext(), pull.Poster, pull.Content) + if err != nil { + return err + } + + notification.NotifyNewPullRequest(pr, mentions) // add first push codes comment baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) diff --git a/services/pull/review.go b/services/pull/review.go index 6781136061..8994a9e78a 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -57,7 +57,12 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models return nil, err } - notification.NotifyCreateIssueComment(doer, issue.Repo, issue, comment) + mentions, err := issue.FindAndUpdateIssueMentions(models.DefaultDBContext(), doer, comment.Content) + if err != nil { + return nil, err + } + + notification.NotifyCreateIssueComment(doer, issue.Repo, issue, comment, mentions) return comment, nil } @@ -226,7 +231,25 @@ func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issu return nil, nil, err } - notification.NotifyPullRequestReview(pr, review, comm) + ctx := models.DefaultDBContext() + mentions, err := issue.FindAndUpdateIssueMentions(ctx, doer, comm.Content) + if err != nil { + return nil, nil, err + } + + notification.NotifyPullRequestReview(pr, review, comm, mentions) + + for _, lines := range review.CodeComments { + for _, comments := range lines { + for _, codeComment := range comments { + mentions, err := issue.FindAndUpdateIssueMentions(ctx, doer, codeComment.Content) + if err != nil { + return nil, nil, err + } + notification.NotifyPullRequestCodeComment(pr, codeComment, mentions) + } + } + } return review, comm, nil } -- cgit v1.2.3