Skip to content
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

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

Merged
merged 8 commits into from
May 25, 2017

Conversation

jonasfranz
Copy link
Member

Reference: #1669

Signed-off-by: Jonas <info@jonasfranz.software>
Added explanation to return statement.

Signed-off-by: Jonas <info@jonasfranz.software>
Added explanation to return statement + documentation.

Signed-off-by: Jonas <info@jonasfranz.software>
Signed-off-by: Jonas Franz <info@jonasfranz.software>
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())
Copy link
Member

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 :)

Copy link
Member

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 <info@jonasfranz.software>
Copy link
Member

@bkcsoft bkcsoft left a comment

Choose a reason for hiding this comment

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

All the changes :trollface:

return fmt.Errorf("PrepareMailToParticipants: %v", err)
}

SendIssueCommentMail(issue, doer, comment, tos)
Copy link
Member

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(...)
}

// 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 {

Copy link
Member

Choose a reason for hiding this comment

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

no newline


names, tos, err := prepareMailToParticipants(issue, doer)

if err != nil {
Copy link
Member

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 checks :)

}

watchers, err := GetWatchers(issue.RepoID)
if err != nil {
return fmt.Errorf("GetWatchers [repo_id: %d]: %v", issue.RepoID, err)
return nil, nil, err
Copy link
Member

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)

}
participants, err := GetParticipantsByIssueID(issue.ID)
if err != nil {
return fmt.Errorf("GetParticipantsByIssueID [issue_id: %d]: %v", issue.ID, err)
return nil, nil, err
Copy link
Member

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 :)

}

// 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) {
Copy link
Member

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?

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
Copy link
Member

Choose a reason for hiding this comment

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

Wrap error

@@ -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 {
Copy link
Member

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

@@ -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)
Copy link
Member

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 <info@jonasfranz.software>
@@ -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)
Copy link
Member

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 <info@jonasfranz.software>
@bkcsoft
Copy link
Member

bkcsoft commented May 4, 2017

LGTM, but untested

@tboerger tboerger added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label May 4, 2017
@@ -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.
Copy link
Member

@lafriks lafriks May 4, 2017

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())
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 🙂

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

@lafriks lafriks left a 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())
Copy link
Member

Choose a reason for hiding this comment

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

Ok

@lunny lunny added this to the 1.2.0 milestone May 5, 2017
@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label May 5, 2017
@lunny
Copy link
Member

lunny commented May 25, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 25, 2017
@lunny lunny merged commit 03912ce into go-gitea:master May 25, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants