-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
Signed-off-by: Jonas <[email protected]>
Added explanation to return statement. Signed-off-by: Jonas <[email protected]>
Added explanation to return statement + documentation. Signed-off-by: Jonas <[email protected]>
Signed-off-by: Jonas Franz <[email protected]>
models/mail.go
Outdated
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() + "#" + comment.HashTag()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's comment.HTMLURL()
to replace issue.HTMLURL() + "#" + comment.HashTag()
... Also go-fmt
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you'd like, you can change comment.HTMLURL()
to do this instead 😄
return fmt.Sprintf("%s#%s", issue.HTMLURL(), c.HashTag())
Signed-off-by: Jonas Franz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes
models/issue_mail.go
Outdated
return fmt.Errorf("PrepareMailToParticipants: %v", err) | ||
} | ||
|
||
SendIssueCommentMail(issue, doer, comment, tos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we merge these 2 (almost identical) functions by doing
if comment != nil {
SendIssueCommentMail(...)
} else {
SendIssueActionMail(...)
}
models/issue_mail.go
Outdated
// 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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no newline
models/issue_mail.go
Outdated
|
||
names, tos, err := prepareMailToParticipants(issue, doer) | ||
|
||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no newline between set and check
s :)
models/issue_mail.go
Outdated
} | ||
|
||
watchers, err := GetWatchers(issue.RepoID) | ||
if err != nil { | ||
return fmt.Errorf("GetWatchers [repo_id: %d]: %v", issue.RepoID, err) | ||
return nil, nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error should still we wrapped:
return nil, nil, fmt.Errorf("GetWatchers [repo_id: %d]: %v", issue.RepoID, err)
models/issue_mail.go
Outdated
} | ||
participants, err := GetParticipantsByIssueID(issue.ID) | ||
if err != nil { | ||
return fmt.Errorf("GetParticipantsByIssueID [issue_id: %d]: %v", issue.ID, err) | ||
return nil, nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, wrap the error :)
models/issue_mail.go
Outdated
} | ||
|
||
// prepareMailToParticipants creates the tos and names list for an issue and the issue's creator. | ||
func prepareMailToParticipants(issue *Issue, doer *User) (tos []string, names []string, error error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really a fan for named returns, got a reason to do that?
models/issue_mail.go
Outdated
for i := range watchers { | ||
if watchers[i].UserID == doer.ID { | ||
continue | ||
} | ||
|
||
to, err := GetUserByID(watchers[i].UserID) | ||
if err != nil { | ||
return fmt.Errorf("GetUserByID [%d]: %v", watchers[i].UserID, err) | ||
return nil, nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap error
models/issue_mail.go
Outdated
@@ -95,7 +135,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 = mailIssueActionToParticipants(issue, issue.Poster, mentions); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you'd just call mailIssueCommentToParticipants(issue, issue.Poster, nil, mentions)
instead
models/issue_mail.go
Outdated
@@ -95,7 +135,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 = mailIssueActionToParticipants(issue, issue.Poster, mentions); err != nil { | |||
log.Error(4, "mailIssueCommentToParticipants: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically wrong here, but maybe not later on ;)
Signed-off-by: Jonas Franz <[email protected]>
models/issue_mail.go
Outdated
@@ -95,7 +104,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 = mailIssueActionToParticipants(issue, issue.Poster, mentions); err != nil { | |||
log.Error(4, "mailIssueCommentToParticipants: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong error-message, otherwise LGTM 🎉
…pants. Signed-off-by: Jonas Franz <[email protected]>
LGTM, but untested |
models/issue_mail.go
Outdated
@@ -18,11 +18,11 @@ func (issue *Issue) mailSubject() string { | |||
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.Name, issue.Title, issue.Index) | |||
} | |||
|
|||
// mailIssueCommentToParticipants can be used for both new issue creation and comment. | |||
// mailIssueCommentToParticipants can be used only for comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this comment be changed back to original?
|
||
data := make(map[string]interface{}, 10) | ||
if comment != nil { | ||
data = composeTplData(subject, body, issue.HTMLURL()+"#"+comment.HashTag()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
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 🙂
Signed-off-by: Jonas Franz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but have to test it
|
||
data := make(map[string]interface{}, 10) | ||
if comment != nil { | ||
data = composeTplData(subject, body, issue.HTMLURL()+"#"+comment.HashTag()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
LGTM |
Reference: #1669