Browse Source

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

* Added comment's hashtag to url for mail notifications.

Signed-off-by: Jonas <info@jonasfranz.software>

* Added comment's hashtag to url for mail notifications.
Added explanation to return statement.

Signed-off-by: Jonas <info@jonasfranz.software>

* Added comment's hashtag to url for mail notifications.
Added explanation to return statement + documentation.

Signed-off-by: Jonas <info@jonasfranz.software>

* Added comment's hashtag to url for mail notifications.

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Replacing in-line link generation with HTMLURL. (+gofmt)

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Replaced action-based model with nil-based model. (+gofmt)

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants.

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Updating comment for mailIssueCommentToParticipants

Signed-off-by: Jonas Franz <info@jonasfranz.software>
tags/v1.2.0-rc1
Jonas Franz 7 years ago
parent
commit
03912ce014
3 changed files with 19 additions and 12 deletions
  1. 2
    2
      models/issue_comment.go
  2. 5
    4
      models/issue_mail.go
  3. 12
    6
      models/mail.go

+ 2
- 2
models/issue_comment.go View File

log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err) log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
return "" 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 // IssueURL formats a URL-string to the issue
case ActionReopenIssue: case ActionReopenIssue:
issue.Content = fmt.Sprintf("Reopened #%d", issue.Index) 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) log.Error(4, "mailIssueCommentToParticipants: %v", err)
} }



+ 5
- 4
models/issue_mail.go View File

// This function sends two list of emails: // This function sends two list of emails:
// 1. Repository watchers and users who are participated in comments. // 1. Repository watchers and users who are participated in comments.
// 2. Users who are not in 1. but get mentioned in current issue/comment. // 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 { if !setting.Service.EnableNotifyMail {
return nil return nil
} }
tos = append(tos, participants[i].Email) tos = append(tos, participants[i].Email)
names = append(names, participants[i].Name) names = append(names, participants[i].Name)
} }
SendIssueCommentMail(issue, doer, tos)

SendIssueCommentMail(issue, doer, comment, tos)


// Mail mentioned people and exclude watchers. // Mail mentioned people and exclude watchers.
names = append(names, doer.Name) names = append(names, doer.Name)


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


return nil return nil
} }
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) 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) log.Error(4, "mailIssueCommentToParticipants: %v", err)
} }



+ 12
- 6
models/mail.go View File

return data 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() subject := issue.mailSubject()
body := string(markdown.RenderString(issue.Content, issue.Repo.HTMLURL(), issue.Repo.ComposeMetas())) 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())
} else {
data = composeTplData(subject, body, issue.HTMLURL())
}
data["Doer"] = doer data["Doer"] = doer


var content bytes.Buffer var content bytes.Buffer
} }


// SendIssueCommentMail composes and sends issue comment emails to target receivers. // 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 { if len(tos) == 0 {
return 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. // 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 { if len(tos) == 0 {
return return
} }
mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueMention, tos, "issue mention"))
mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueMention, tos, "issue mention"))
} }

Loading…
Cancel
Save