Skip to content

Adding #issuecomment to the URL in E-Mail notifications #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 25, 2017
4 changes: 2 additions & 2 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (c *Comment) HTMLURL() string {
log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
return ""
}
return fmt.Sprintf("%s#issuecomment-%d", issue.HTMLURL(), c.ID)
return fmt.Sprintf("%s#%s", issue.HTMLURL(), c.HashTag())
}

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

Expand Down
9 changes: 5 additions & 4 deletions models/issue_mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (issue *Issue) mailSubject() string {
// This function sends two list of emails:
// 1. Repository watchers and users who are participated in comments.
// 2. Users who are not in 1. but get mentioned in current issue/comment.
func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) error {
func mailIssueCommentToParticipants(issue *Issue, doer *User, comment *Comment, mentions []string) error {
if !setting.Service.EnableNotifyMail {
return nil
}
Expand Down Expand Up @@ -70,7 +70,8 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
tos = append(tos, participants[i].Email)
names = append(names, participants[i].Name)
}
SendIssueCommentMail(issue, doer, tos)

SendIssueCommentMail(issue, doer, comment, tos)

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

tos = append(tos, mentions[i])
}
SendIssueMentionMail(issue, doer, GetUserEmailsByNames(tos))
SendIssueMentionMail(issue, doer, comment, GetUserEmailsByNames(tos))

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

if err = mailIssueCommentToParticipants(issue, issue.Poster, mentions); err != nil {
if err = mailIssueCommentToParticipants(issue, issue.Poster, nil, mentions); err != nil {
log.Error(4, "mailIssueCommentToParticipants: %v", err)
}

Expand Down
18 changes: 12 additions & 6 deletions models/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,16 @@ func composeTplData(subject, body, link string) map[string]interface{} {
return data
}

func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []string, info string) *mailer.Message {
func composeIssueCommentMessage(issue *Issue, doer *User, comment *Comment, tplName base.TplName, tos []string, info string) *mailer.Message {
subject := issue.mailSubject()
body := string(markdown.RenderString(issue.Content, issue.Repo.HTMLURL(), issue.Repo.ComposeMetas()))
data := composeTplData(subject, body, issue.HTMLURL())

data := make(map[string]interface{}, 10)
if comment != nil {
data = composeTplData(subject, body, issue.HTMLURL()+"#"+comment.HashTag())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why comment.HTMLURL is not used here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because comment.HTMLURL returns an empty string by printing an error to the console (see gitter chat).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonasFranzDEV Gitter chat is not searchable, mind sharing with the rest of the class? As I'm quite sure there's a better solution to this than re-implementing the wheel 🙂

} else {
data = composeTplData(subject, body, issue.HTMLURL())
}
data["Doer"] = doer

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

// SendIssueCommentMail composes and sends issue comment emails to target receivers.
func SendIssueCommentMail(issue *Issue, doer *User, tos []string) {
func SendIssueCommentMail(issue *Issue, doer *User, comment *Comment, tos []string) {
if len(tos) == 0 {
return
}

mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueComment, tos, "issue comment"))
mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueComment, tos, "issue comment"))
}

// SendIssueMentionMail composes and sends issue mention emails to target receivers.
func SendIssueMentionMail(issue *Issue, doer *User, tos []string) {
func SendIssueMentionMail(issue *Issue, doer *User, comment *Comment, tos []string) {
if len(tos) == 0 {
return
}
mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueMention, tos, "issue mention"))
mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueMention, tos, "issue mention"))
}