選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mail.go 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package mail
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/notification/base"
  10. "code.gitea.io/gitea/services/mailer"
  11. )
  12. type mailNotifier struct {
  13. base.NullNotifier
  14. }
  15. var (
  16. _ base.Notifier = &mailNotifier{}
  17. )
  18. // NewNotifier create a new mailNotifier notifier
  19. func NewNotifier() base.Notifier {
  20. return &mailNotifier{}
  21. }
  22. func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  23. issue *models.Issue, comment *models.Comment) {
  24. var act models.ActionType
  25. if comment.Type == models.CommentTypeClose {
  26. act = models.ActionCloseIssue
  27. } else if comment.Type == models.CommentTypeReopen {
  28. act = models.ActionReopenIssue
  29. } else if comment.Type == models.CommentTypeComment {
  30. act = models.ActionCommentIssue
  31. } else if comment.Type == models.CommentTypeCode {
  32. act = models.ActionCommentIssue
  33. }
  34. if err := mailer.MailParticipantsComment(comment, act, issue); err != nil {
  35. log.Error("MailParticipantsComment: %v", err)
  36. }
  37. }
  38. func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
  39. if err := mailer.MailParticipants(issue, issue.Poster, models.ActionCreateIssue); err != nil {
  40. log.Error("MailParticipants: %v", err)
  41. }
  42. }
  43. func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
  44. var actionType models.ActionType
  45. issue.Content = ""
  46. if issue.IsPull {
  47. if isClosed {
  48. actionType = models.ActionClosePullRequest
  49. } else {
  50. actionType = models.ActionReopenPullRequest
  51. }
  52. } else {
  53. if isClosed {
  54. actionType = models.ActionCloseIssue
  55. } else {
  56. actionType = models.ActionReopenIssue
  57. }
  58. }
  59. if err := mailer.MailParticipants(issue, doer, actionType); err != nil {
  60. log.Error("MailParticipants: %v", err)
  61. }
  62. }
  63. func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
  64. if err := mailer.MailParticipants(pr.Issue, pr.Issue.Poster, models.ActionCreatePullRequest); err != nil {
  65. log.Error("MailParticipants: %v", err)
  66. }
  67. }
  68. func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment) {
  69. var act models.ActionType
  70. if comment.Type == models.CommentTypeClose {
  71. act = models.ActionCloseIssue
  72. } else if comment.Type == models.CommentTypeReopen {
  73. act = models.ActionReopenIssue
  74. } else if comment.Type == models.CommentTypeComment {
  75. act = models.ActionCommentPull
  76. }
  77. if err := mailer.MailParticipantsComment(comment, act, pr.Issue); err != nil {
  78. log.Error("MailParticipantsComment: %v", err)
  79. }
  80. }
  81. func (m *mailNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
  82. // mail only sent to added assignees and not self-assignee
  83. if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == models.EmailNotificationsEnabled {
  84. ct := fmt.Sprintf("Assigned #%d.", issue.Index)
  85. mailer.SendIssueAssignedMail(issue, doer, ct, comment, []string{assignee.Email})
  86. }
  87. }
  88. func (m *mailNotifier) NotifyPullRewiewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
  89. if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() == models.EmailNotificationsEnabled {
  90. ct := fmt.Sprintf("Requested to review #%d.", issue.Index)
  91. mailer.SendIssueAssignedMail(issue, doer, ct, comment, []string{reviewer.Email})
  92. }
  93. }
  94. func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
  95. if err := pr.LoadIssue(); err != nil {
  96. log.Error("pr.LoadIssue: %v", err)
  97. return
  98. }
  99. pr.Issue.Content = ""
  100. if err := mailer.MailParticipants(pr.Issue, doer, models.ActionMergePullRequest); err != nil {
  101. log.Error("MailParticipants: %v", err)
  102. }
  103. }