]> source.dussan.org Git - gitea.git/commitdiff
Don't manipulate input params in email notification (#16011)
authorJimmy Praet <jimmy.praet@telenet.be>
Sun, 30 May 2021 09:38:38 +0000 (11:38 +0200)
committerGitHub <noreply@github.com>
Sun, 30 May 2021 09:38:38 +0000 (10:38 +0100)
modules/notification/mail/mail.go
services/mailer/mail_comment.go
services/mailer/mail_issue.go

index eb45409faf277371dd24f628bf165f9cb1339994..0927e182c18b8e42343a886cfd1af97b89dc894b 100644 (file)
@@ -54,7 +54,6 @@ func (m *mailNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.Us
 
 func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
        var actionType models.ActionType
-       issue.Content = ""
        if issue.IsPull {
                if isClosed {
                        actionType = models.ActionClosePullRequest
@@ -124,7 +123,6 @@ func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode
                log.Error("pr.LoadIssue: %v", err)
                return
        }
-       pr.Issue.Content = ""
        if err := mailer.MailParticipants(pr.Issue, doer, models.ActionMergePullRequest, nil); err != nil {
                log.Error("MailParticipants: %v", err)
        }
@@ -151,8 +149,6 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *model
        if err := comment.LoadPushCommits(); err != nil {
                log.Error("comment.LoadPushCommits: %v", err)
        }
-       comment.Content = ""
-
        m.NotifyCreateIssueComment(doer, comment.Issue.Repo, comment.Issue, comment, nil)
 }
 
index f73c9fb6372f942104984417e60f99305d9309d0..eca05cef2960d844fe376faf33919a9387ad9210 100644 (file)
@@ -11,12 +11,16 @@ import (
 
 // MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
 func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*models.User) error {
+       content := c.Content
+       if c.Type == models.CommentTypePullPush {
+               content = ""
+       }
        if err := mailIssueCommentToParticipants(
                &mailCommentContext{
                        Issue:      issue,
                        Doer:       c.Poster,
                        ActionType: opType,
-                       Content:    c.Content,
+                       Content:    content,
                        Comment:    c,
                }, mentions); err != nil {
                log.Error("mailIssueCommentToParticipants: %v", err)
index cf5265872b3fb6e522119d02e84962ac85f73599..867aa32517502babb8e2f3b0fbb9f83ef2b19360 100644 (file)
@@ -161,12 +161,18 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*models.User, visite
 // MailParticipants sends new issue thread created emails to repository watchers
 // and mentioned people.
 func MailParticipants(issue *models.Issue, doer *models.User, opType models.ActionType, mentions []*models.User) error {
+       content := issue.Content
+       if opType == models.ActionCloseIssue || opType == models.ActionClosePullRequest ||
+               opType == models.ActionReopenIssue || opType == models.ActionReopenPullRequest ||
+               opType == models.ActionMergePullRequest {
+               content = ""
+       }
        if err := mailIssueCommentToParticipants(
                &mailCommentContext{
                        Issue:      issue,
                        Doer:       doer,
                        ActionType: opType,
-                       Content:    issue.Content,
+                       Content:    content,
                        Comment:    nil,
                }, mentions); err != nil {
                log.Error("mailIssueCommentToParticipants: %v", err)