Skip to content

Commit 499a8a1

Browse files
silverwindzeripath
authored andcommitted
Various fixes for issue mail notifications (#7165)
- Send individual mails for actions and comments - Send mail for new issues/prs without a comment - Use correct sender for reopen/close actions - Hopefully fixed all bugs related to missing mails Fixes: #7124 Fixes: #5977
1 parent 74690f6 commit 499a8a1

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

models/issue_comment.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,23 @@ func (c *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (e
403403
return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
404404
}
405405

406-
content := c.Content
406+
if len(c.Content) > 0 {
407+
if err = mailIssueCommentToParticipants(e, issue, c.Poster, c.Content, c, mentions); err != nil {
408+
log.Error("mailIssueCommentToParticipants: %v", err)
409+
}
410+
}
407411

408412
switch opType {
409413
case ActionCloseIssue:
410-
content = fmt.Sprintf("Closed #%d", issue.Index)
414+
ct := fmt.Sprintf("Closed #%d.", issue.Index)
415+
if err = mailIssueCommentToParticipants(e, issue, c.Poster, ct, c, mentions); err != nil {
416+
log.Error("mailIssueCommentToParticipants: %v", err)
417+
}
411418
case ActionReopenIssue:
412-
content = fmt.Sprintf("Reopened #%d", issue.Index)
413-
}
414-
if err = mailIssueCommentToParticipants(e, issue, c.Poster, content, c, mentions); err != nil {
415-
log.Error("mailIssueCommentToParticipants: %v", err)
419+
ct := fmt.Sprintf("Reopened #%d.", issue.Index)
420+
if err = mailIssueCommentToParticipants(e, issue, c.Poster, ct, c, mentions); err != nil {
421+
log.Error("mailIssueCommentToParticipants: %v", err)
422+
}
416423
}
417424

418425
return nil

models/issue_mail.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,41 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content
118118

119119
// MailParticipants sends new issue thread created emails to repository watchers
120120
// and mentioned people.
121-
func (issue *Issue) MailParticipants(opType ActionType) (err error) {
122-
return issue.mailParticipants(x, opType)
121+
func (issue *Issue) MailParticipants(doer *User, opType ActionType) (err error) {
122+
return issue.mailParticipants(x, doer, opType)
123123
}
124124

125-
func (issue *Issue) mailParticipants(e Engine, opType ActionType) (err error) {
125+
func (issue *Issue) mailParticipants(e Engine, doer *User, opType ActionType) (err error) {
126126
mentions := markup.FindAllMentions(issue.Content)
127+
127128
if err = UpdateIssueMentions(e, issue.ID, mentions); err != nil {
128129
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
129130
}
130131

131-
var content = issue.Content
132+
if len(issue.Content) > 0 {
133+
if err = mailIssueCommentToParticipants(e, issue, doer, issue.Content, nil, mentions); err != nil {
134+
log.Error("mailIssueCommentToParticipants: %v", err)
135+
}
136+
}
137+
132138
switch opType {
139+
case ActionCreateIssue, ActionCreatePullRequest:
140+
if len(issue.Content) == 0 {
141+
ct := fmt.Sprintf("Created #%d.", issue.Index)
142+
if err = mailIssueCommentToParticipants(e, issue, doer, ct, nil, mentions); err != nil {
143+
log.Error("mailIssueCommentToParticipants: %v", err)
144+
}
145+
}
133146
case ActionCloseIssue, ActionClosePullRequest:
134-
content = fmt.Sprintf("Closed #%d", issue.Index)
147+
ct := fmt.Sprintf("Closed #%d.", issue.Index)
148+
if err = mailIssueCommentToParticipants(e, issue, doer, ct, nil, mentions); err != nil {
149+
log.Error("mailIssueCommentToParticipants: %v", err)
150+
}
135151
case ActionReopenIssue, ActionReopenPullRequest:
136-
content = fmt.Sprintf("Reopened #%d", issue.Index)
137-
}
138-
139-
if err = mailIssueCommentToParticipants(e, issue, issue.Poster, content, nil, mentions); err != nil {
140-
log.Error("mailIssueCommentToParticipants: %v", err)
152+
ct := fmt.Sprintf("Reopened #%d.", issue.Index)
153+
if err = mailIssueCommentToParticipants(e, issue, doer, ct, nil, mentions); err != nil {
154+
log.Error("mailIssueCommentToParticipants: %v", err)
155+
}
141156
}
142157

143158
return nil

modules/notification/mail/mail.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.
4242
}
4343

4444
func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
45-
if err := issue.MailParticipants(models.ActionCreateIssue); err != nil {
45+
if err := issue.MailParticipants(issue.Poster, models.ActionCreateIssue); err != nil {
4646
log.Error("MailParticipants: %v", err)
4747
}
4848
}
@@ -63,13 +63,13 @@ func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.
6363
}
6464
}
6565

66-
if err := issue.MailParticipants(actionType); err != nil {
66+
if err := issue.MailParticipants(doer, actionType); err != nil {
6767
log.Error("MailParticipants: %v", err)
6868
}
6969
}
7070

7171
func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
72-
if err := pr.Issue.MailParticipants(models.ActionCreatePullRequest); err != nil {
72+
if err := pr.Issue.MailParticipants(pr.Issue.Poster, models.ActionCreatePullRequest); err != nil {
7373
log.Error("MailParticipants: %v", err)
7474
}
7575
}

0 commit comments

Comments
 (0)