Skip to content

Commit 4b87aa3

Browse files
lunnyzeripath
authored andcommitted
fix mail notification when close/reopen issue (#6581) (#6588)
1 parent 72f4cdf commit 4b87aa3

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

models/issue_mail.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,25 @@ 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() (err error) {
122-
return issue.mailParticipants(x)
121+
func (issue *Issue) MailParticipants(opType ActionType) (err error) {
122+
return issue.mailParticipants(x, opType)
123123
}
124124

125-
func (issue *Issue) mailParticipants(e Engine) (err error) {
125+
func (issue *Issue) mailParticipants(e Engine, opType ActionType) (err error) {
126126
mentions := markup.FindAllMentions(issue.Content)
127127
if err = UpdateIssueMentions(e, issue.ID, mentions); err != nil {
128128
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
129129
}
130130

131-
if err = mailIssueCommentToParticipants(e, issue, issue.Poster, issue.Content, nil, mentions); err != nil {
131+
var content = issue.Content
132+
switch opType {
133+
case ActionCloseIssue, ActionClosePullRequest:
134+
content = fmt.Sprintf("Closed #%d", issue.Index)
135+
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 {
132140
log.Error(4, "mailIssueCommentToParticipants: %v", err)
133141
}
134142

modules/notification/mail/mail.go

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

4444
func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
45-
if err := issue.MailParticipants(); err != nil {
45+
if err := issue.MailParticipants(models.ActionCreateIssue); err != nil {
4646
log.Error(4, "MailParticipants: %v", err)
4747
}
4848
}
4949

5050
func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
51-
if err := issue.MailParticipants(); err != nil {
51+
var actionType models.ActionType
52+
if issue.IsPull {
53+
if isClosed {
54+
actionType = models.ActionClosePullRequest
55+
} else {
56+
actionType = models.ActionReopenPullRequest
57+
}
58+
} else {
59+
if isClosed {
60+
actionType = models.ActionCloseIssue
61+
} else {
62+
actionType = models.ActionReopenIssue
63+
}
64+
}
65+
66+
if err := issue.MailParticipants(actionType); err != nil {
5267
log.Error(4, "MailParticipants: %v", err)
5368
}
5469
}
5570

5671
func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
57-
if err := pr.Issue.MailParticipants(); err != nil {
72+
if err := pr.Issue.MailParticipants(models.ActionCreatePullRequest); err != nil {
5873
log.Error(4, "MailParticipants: %v", err)
5974
}
6075
}

0 commit comments

Comments
 (0)