本站源代码
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

101 lines
3.1KB

  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("MailParticipants: %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, isClosed bool) {
  44. var actionType models.ActionType
  45. if issue.IsPull {
  46. if isClosed {
  47. actionType = models.ActionClosePullRequest
  48. } else {
  49. actionType = models.ActionReopenPullRequest
  50. }
  51. } else {
  52. if isClosed {
  53. actionType = models.ActionCloseIssue
  54. } else {
  55. actionType = models.ActionReopenIssue
  56. }
  57. }
  58. if err := mailer.MailParticipants(issue, doer, actionType); err != nil {
  59. log.Error("MailParticipants: %v", err)
  60. }
  61. }
  62. func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
  63. if err := mailer.MailParticipants(pr.Issue, pr.Issue.Poster, models.ActionCreatePullRequest); err != nil {
  64. log.Error("MailParticipants: %v", err)
  65. }
  66. }
  67. func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment) {
  68. var act models.ActionType
  69. if comment.Type == models.CommentTypeClose {
  70. act = models.ActionCloseIssue
  71. } else if comment.Type == models.CommentTypeReopen {
  72. act = models.ActionReopenIssue
  73. } else if comment.Type == models.CommentTypeComment {
  74. act = models.ActionCommentIssue
  75. }
  76. if err := mailer.MailParticipantsComment(comment, act, pr.Issue); err != nil {
  77. log.Error("MailParticipants: %v", err)
  78. }
  79. }
  80. func (m *mailNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
  81. // mail only sent to added assignees and not self-assignee
  82. if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == models.EmailNotificationsEnabled {
  83. ct := fmt.Sprintf("Assigned #%d.", issue.Index)
  84. mailer.SendIssueAssignedMail(issue, doer, ct, comment, []string{assignee.Email})
  85. }
  86. }
上海开阖软件有限公司 沪ICP备12045867号-1