mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-09-06 22:33:14 +00:00
Various fixes for issue mail notifications (#7165)
- Send individual mails for actions and comments - Send mail for new issues/prs without a comment - Use correct sender for reopen/close actions - Hopefully fixed all bugs related to missing mails Fixes: https://github.com/go-gitea/gitea/issues/7124 Fixes: https://github.com/go-gitea/gitea/issues/5977
This commit is contained in:
parent
74690f6451
commit
499a8a1cdd
3 changed files with 42 additions and 20 deletions
|
@ -403,17 +403,24 @@ func (c *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (e
|
||||||
return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
|
return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
content := c.Content
|
if len(c.Content) > 0 {
|
||||||
|
if err = mailIssueCommentToParticipants(e, issue, c.Poster, c.Content, c, mentions); err != nil {
|
||||||
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch opType {
|
switch opType {
|
||||||
case ActionCloseIssue:
|
case ActionCloseIssue:
|
||||||
content = fmt.Sprintf("Closed #%d", issue.Index)
|
ct := fmt.Sprintf("Closed #%d.", issue.Index)
|
||||||
case ActionReopenIssue:
|
if err = mailIssueCommentToParticipants(e, issue, c.Poster, ct, c, mentions); err != nil {
|
||||||
content = fmt.Sprintf("Reopened #%d", issue.Index)
|
|
||||||
}
|
|
||||||
if err = mailIssueCommentToParticipants(e, issue, c.Poster, content, c, mentions); err != nil {
|
|
||||||
log.Error("mailIssueCommentToParticipants: %v", err)
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||||
}
|
}
|
||||||
|
case ActionReopenIssue:
|
||||||
|
ct := fmt.Sprintf("Reopened #%d.", issue.Index)
|
||||||
|
if err = mailIssueCommentToParticipants(e, issue, c.Poster, ct, c, mentions); err != nil {
|
||||||
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,27 +118,42 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content
|
||||||
|
|
||||||
// MailParticipants sends new issue thread created emails to repository watchers
|
// MailParticipants sends new issue thread created emails to repository watchers
|
||||||
// and mentioned people.
|
// and mentioned people.
|
||||||
func (issue *Issue) MailParticipants(opType ActionType) (err error) {
|
func (issue *Issue) MailParticipants(doer *User, opType ActionType) (err error) {
|
||||||
return issue.mailParticipants(x, opType)
|
return issue.mailParticipants(x, doer, opType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (issue *Issue) mailParticipants(e Engine, opType ActionType) (err error) {
|
func (issue *Issue) mailParticipants(e Engine, doer *User, opType ActionType) (err error) {
|
||||||
mentions := markup.FindAllMentions(issue.Content)
|
mentions := markup.FindAllMentions(issue.Content)
|
||||||
|
|
||||||
if err = UpdateIssueMentions(e, issue.ID, mentions); err != nil {
|
if err = UpdateIssueMentions(e, issue.ID, mentions); err != nil {
|
||||||
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
|
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var content = issue.Content
|
if len(issue.Content) > 0 {
|
||||||
switch opType {
|
if err = mailIssueCommentToParticipants(e, issue, doer, issue.Content, nil, mentions); err != nil {
|
||||||
case ActionCloseIssue, ActionClosePullRequest:
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||||
content = fmt.Sprintf("Closed #%d", issue.Index)
|
}
|
||||||
case ActionReopenIssue, ActionReopenPullRequest:
|
|
||||||
content = fmt.Sprintf("Reopened #%d", issue.Index)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = mailIssueCommentToParticipants(e, issue, issue.Poster, content, nil, mentions); err != nil {
|
switch opType {
|
||||||
|
case ActionCreateIssue, ActionCreatePullRequest:
|
||||||
|
if len(issue.Content) == 0 {
|
||||||
|
ct := fmt.Sprintf("Created #%d.", issue.Index)
|
||||||
|
if err = mailIssueCommentToParticipants(e, issue, doer, ct, nil, mentions); err != nil {
|
||||||
log.Error("mailIssueCommentToParticipants: %v", err)
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
case ActionCloseIssue, ActionClosePullRequest:
|
||||||
|
ct := fmt.Sprintf("Closed #%d.", issue.Index)
|
||||||
|
if err = mailIssueCommentToParticipants(e, issue, doer, ct, nil, mentions); err != nil {
|
||||||
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||||
|
}
|
||||||
|
case ActionReopenIssue, ActionReopenPullRequest:
|
||||||
|
ct := fmt.Sprintf("Reopened #%d.", issue.Index)
|
||||||
|
if err = mailIssueCommentToParticipants(e, issue, doer, ct, nil, mentions); err != nil {
|
||||||
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
|
func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
if err := issue.MailParticipants(models.ActionCreateIssue); err != nil {
|
if err := issue.MailParticipants(issue.Poster, models.ActionCreateIssue); err != nil {
|
||||||
log.Error("MailParticipants: %v", err)
|
log.Error("MailParticipants: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,13 @@ func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.MailParticipants(actionType); err != nil {
|
if err := issue.MailParticipants(doer, actionType); err != nil {
|
||||||
log.Error("MailParticipants: %v", err)
|
log.Error("MailParticipants: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
if err := pr.Issue.MailParticipants(models.ActionCreatePullRequest); err != nil {
|
if err := pr.Issue.MailParticipants(pr.Issue.Poster, models.ActionCreatePullRequest); err != nil {
|
||||||
log.Error("MailParticipants: %v", err)
|
log.Error("MailParticipants: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue