Skip to content

Commit 03912ce

Browse files
jonasfranzlunny
authored andcommitted
Adding #issuecomment to the URL in E-Mail notifications (#1674)
* Added comment's hashtag to url for mail notifications. Signed-off-by: Jonas <[email protected]> * Added comment's hashtag to url for mail notifications. Added explanation to return statement. Signed-off-by: Jonas <[email protected]> * Added comment's hashtag to url for mail notifications. Added explanation to return statement + documentation. Signed-off-by: Jonas <[email protected]> * Added comment's hashtag to url for mail notifications. Signed-off-by: Jonas Franz <[email protected]> * Replacing in-line link generation with HTMLURL. (+gofmt) Signed-off-by: Jonas Franz <[email protected]> * Replaced action-based model with nil-based model. (+gofmt) Signed-off-by: Jonas Franz <[email protected]> * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. Signed-off-by: Jonas Franz <[email protected]> * Updating comment for mailIssueCommentToParticipants Signed-off-by: Jonas Franz <[email protected]>
1 parent cb74f1b commit 03912ce

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

models/issue_comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (c *Comment) HTMLURL() string {
153153
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
154154
return ""
155155
}
156-
return fmt.Sprintf("%s#issuecomment-%d", issue.HTMLURL(), c.ID)
156+
return fmt.Sprintf("%s#%s", issue.HTMLURL(), c.HashTag())
157157
}
158158

159159
// IssueURL formats a URL-string to the issue
@@ -289,7 +289,7 @@ func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (e
289289
case ActionReopenIssue:
290290
issue.Content = fmt.Sprintf("Reopened #%d", issue.Index)
291291
}
292-
if err = mailIssueCommentToParticipants(issue, c.Poster, mentions); err != nil {
292+
if err = mailIssueCommentToParticipants(issue, c.Poster, c, mentions); err != nil {
293293
log.Error(4, "mailIssueCommentToParticipants: %v", err)
294294
}
295295

models/issue_mail.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (issue *Issue) mailSubject() string {
2222
// This function sends two list of emails:
2323
// 1. Repository watchers and users who are participated in comments.
2424
// 2. Users who are not in 1. but get mentioned in current issue/comment.
25-
func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) error {
25+
func mailIssueCommentToParticipants(issue *Issue, doer *User, comment *Comment, mentions []string) error {
2626
if !setting.Service.EnableNotifyMail {
2727
return nil
2828
}
@@ -70,7 +70,8 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
7070
tos = append(tos, participants[i].Email)
7171
names = append(names, participants[i].Name)
7272
}
73-
SendIssueCommentMail(issue, doer, tos)
73+
74+
SendIssueCommentMail(issue, doer, comment, tos)
7475

7576
// Mail mentioned people and exclude watchers.
7677
names = append(names, doer.Name)
@@ -82,7 +83,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
8283

8384
tos = append(tos, mentions[i])
8485
}
85-
SendIssueMentionMail(issue, doer, GetUserEmailsByNames(tos))
86+
SendIssueMentionMail(issue, doer, comment, GetUserEmailsByNames(tos))
8687

8788
return nil
8889
}
@@ -95,7 +96,7 @@ func (issue *Issue) MailParticipants() (err error) {
9596
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
9697
}
9798

98-
if err = mailIssueCommentToParticipants(issue, issue.Poster, mentions); err != nil {
99+
if err = mailIssueCommentToParticipants(issue, issue.Poster, nil, mentions); err != nil {
99100
log.Error(4, "mailIssueCommentToParticipants: %v", err)
100101
}
101102

models/mail.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,16 @@ func composeTplData(subject, body, link string) map[string]interface{} {
148148
return data
149149
}
150150

151-
func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []string, info string) *mailer.Message {
151+
func composeIssueCommentMessage(issue *Issue, doer *User, comment *Comment, tplName base.TplName, tos []string, info string) *mailer.Message {
152152
subject := issue.mailSubject()
153153
body := string(markdown.RenderString(issue.Content, issue.Repo.HTMLURL(), issue.Repo.ComposeMetas()))
154-
data := composeTplData(subject, body, issue.HTMLURL())
154+
155+
data := make(map[string]interface{}, 10)
156+
if comment != nil {
157+
data = composeTplData(subject, body, issue.HTMLURL()+"#"+comment.HashTag())
158+
} else {
159+
data = composeTplData(subject, body, issue.HTMLURL())
160+
}
155161
data["Doer"] = doer
156162

157163
var content bytes.Buffer
@@ -166,18 +172,18 @@ func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []s
166172
}
167173

168174
// SendIssueCommentMail composes and sends issue comment emails to target receivers.
169-
func SendIssueCommentMail(issue *Issue, doer *User, tos []string) {
175+
func SendIssueCommentMail(issue *Issue, doer *User, comment *Comment, tos []string) {
170176
if len(tos) == 0 {
171177
return
172178
}
173179

174-
mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueComment, tos, "issue comment"))
180+
mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueComment, tos, "issue comment"))
175181
}
176182

177183
// SendIssueMentionMail composes and sends issue mention emails to target receivers.
178-
func SendIssueMentionMail(issue *Issue, doer *User, tos []string) {
184+
func SendIssueMentionMail(issue *Issue, doer *User, comment *Comment, tos []string) {
179185
if len(tos) == 0 {
180186
return
181187
}
182-
mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueMention, tos, "issue mention"))
188+
mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueMention, tos, "issue mention"))
183189
}

0 commit comments

Comments
 (0)