diff --git a/models/issue_comment.go b/models/issue_comment.go index 63f5f6b7788da..64d6c6449a83f 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -1013,10 +1013,6 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review return nil, err } - if err := CommentList(comments).loadPosters(e); err != nil { - return nil, err - } - if err := issue.loadRepo(e); err != nil { return nil, err } diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go index 0900c6dcdf124..a87e31bd2cd46 100644 --- a/modules/notification/mail/mail.go +++ b/modules/notification/mail/mail.go @@ -86,8 +86,14 @@ func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models } else if comment.Type == models.CommentTypeComment { act = models.ActionCommentIssue } + if r != nil { + comment.Review = r + if err := r.LoadCodeComments(); err != nil { + log.Error("LoadCodeComments: %v", err) + } + } if err := mailer.MailParticipantsComment(comment, act, pr.Issue); err != nil { - log.Error("MailParticipants: %v", err) + log.Error("MailParticipantsComment: %v", err) } } diff --git a/routers/repo/pull_review.go b/routers/repo/pull_review.go index 7d030988fd93a..bad1ceb65ed5f 100644 --- a/routers/repo/pull_review.go +++ b/routers/repo/pull_review.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" comment_service "code.gitea.io/gitea/services/comments" - pull_service "code.gitea.io/gitea/services/pull" ) // CreateCodeComment will create a code comment including an pending review if required @@ -55,7 +54,7 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) { } // No pending review exists // Create a new pending review for this issue & user - if review, err = pull_service.CreateReview(models.CreateReviewOptions{ + if review, err = models.CreateReview(models.CreateReviewOptions{ Type: models.ReviewTypePending, Reviewer: ctx.User, Issue: issue, @@ -157,7 +156,7 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) { return } // No current review. Create a new one! - if review, err = pull_service.CreateReview(models.CreateReviewOptions{ + if review, err = models.CreateReview(models.CreateReviewOptions{ Type: reviewType, Issue: issue, Reviewer: ctx.User, @@ -169,7 +168,7 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) { } else { review.Content = form.Content review.Type = reviewType - if err = pull_service.UpdateReview(review); err != nil { + if err = models.UpdateReview(review); err != nil { ctx.ServerError("UpdateReview", err) return } diff --git a/services/mailer/mail.go b/services/mailer/mail.go index fc892f6076b1c..2afb5367a6ff6 100644 --- a/services/mailer/mail.go +++ b/services/mailer/mail.go @@ -44,6 +44,15 @@ var ( subjectRemoveSpaces = regexp.MustCompile(`[\s]+`) ) +// CodeComment contains a single comment within a review +type CodeComment struct { + Path string + Line int64 + Content string + Patch string + Author *models.User +} + // InitMailRender initializes the mail renderer func InitMailRender(subjectTpl *texttmpl.Template, bodyTpl *template.Template) { subjectTemplates = subjectTpl @@ -177,7 +186,8 @@ func composeIssueCommentMessage(issue *models.Issue, doer *models.User, actionTy link string prefix string // Fall back subject for bad templates, make sure subject is never empty - fallback string + fallback string + reviewComments []CodeComment ) commentType := models.CommentTypeComment @@ -190,12 +200,18 @@ func composeIssueCommentMessage(issue *models.Issue, doer *models.User, actionTy } fallback = prefix + fallbackMailSubject(issue) + url := issue.Repo.HTMLURL() + metas := issue.Repo.ComposeMetas() // This is the body of the new issue or comment, not the mail body - body := string(markup.RenderByType(markdown.MarkupName, []byte(content), issue.Repo.HTMLURL(), issue.Repo.ComposeMetas())) + body := string(markup.RenderByType(markdown.MarkupName, []byte(content), url, metas)) actType, actName, tplName := actionToTemplate(issue, actionType, commentType) + if actName == "review" && comment.Review != nil { + reviewComments = getReviewComments(comment.Review) + } + mailMeta := map[string]interface{}{ "FallbackSubject": fallback, "Body": body, @@ -210,6 +226,7 @@ func composeIssueCommentMessage(issue *models.Issue, doer *models.User, actionTy "SubjectPrefix": prefix, "ActionType": actType, "ActionName": actName, + "ReviewComments": reviewComments, } var mailSubject bytes.Buffer @@ -244,6 +261,24 @@ func composeIssueCommentMessage(issue *models.Issue, doer *models.User, actionTy return msg } +func getReviewComments(r *models.Review) []CodeComment { + reviewComments := make([]CodeComment, 0, 10) + for _, lines := range r.CodeComments { + for _, comments := range lines { + for _, comment := range comments { + reviewComments = append(reviewComments, CodeComment{ + Path: comment.TreePath, + Line: comment.Line, + Content: comment.RenderedContent, + Patch: comment.Patch, + Author: comment.Poster, + }) + } + } + } + return reviewComments +} + func sanitizeSubject(subject string) string { runes := []rune(strings.TrimSpace(subjectRemoveSpaces.ReplaceAllLiteralString(subject, " "))) if len(runes) > mailMaxSubjectRunes { diff --git a/services/pull/review.go b/services/pull/review.go deleted file mode 100644 index e4aae3c0d5885..0000000000000 --- a/services/pull/review.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2019 The Gitea Authors. -// All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package pull - -import ( - "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/notification" -) - -// CreateReview creates a new review based on opts -func CreateReview(opts models.CreateReviewOptions) (*models.Review, error) { - review, err := models.CreateReview(opts) - if err != nil { - return nil, err - } - - notification.NotifyPullRequestReview(review.Issue.PullRequest, review, nil) - - return review, nil -} - -// UpdateReview updates a review -func UpdateReview(review *models.Review) error { - err := models.UpdateReview(review) - if err != nil { - return err - } - - notification.NotifyPullRequestReview(review.Issue.PullRequest, review, nil) - - return nil -} diff --git a/templates/mail/issue/default.tmpl b/templates/mail/issue/default.tmpl index ee15d6d8e1cc0..f2b5c5baf8bc8 100644 --- a/templates/mail/issue/default.tmpl +++ b/templates/mail/issue/default.tmpl @@ -3,6 +3,12 @@
{{.Patch}}+
---