You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/log"
  8. "code.gitea.io/gitea/modules/notification/base"
  9. "code.gitea.io/gitea/services/mailer"
  10. )
  11. type mailNotifier struct {
  12. base.NullNotifier
  13. }
  14. var (
  15. _ base.Notifier = &mailNotifier{}
  16. )
  17. // NewNotifier create a new mailNotifier notifier
  18. func NewNotifier() base.Notifier {
  19. return &mailNotifier{}
  20. }
  21. func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  22. issue *models.Issue, comment *models.Comment) {
  23. var act models.ActionType
  24. if comment.Type == models.CommentTypeClose {
  25. act = models.ActionCloseIssue
  26. } else if comment.Type == models.CommentTypeReopen {
  27. act = models.ActionReopenIssue
  28. } else if comment.Type == models.CommentTypeComment {
  29. act = models.ActionCommentIssue
  30. } else if comment.Type == models.CommentTypeCode {
  31. act = models.ActionCommentIssue
  32. }
  33. if err := mailer.MailParticipantsComment(comment, act, issue); err != nil {
  34. log.Error("MailParticipants: %v", err)
  35. }
  36. }
  37. func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
  38. if err := mailer.MailParticipants(issue, issue.Poster, models.ActionCreateIssue); err != nil {
  39. log.Error("MailParticipants: %v", err)
  40. }
  41. }
  42. func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
  43. var actionType models.ActionType
  44. if issue.IsPull {
  45. if isClosed {
  46. actionType = models.ActionClosePullRequest
  47. } else {
  48. actionType = models.ActionReopenPullRequest
  49. }
  50. } else {
  51. if isClosed {
  52. actionType = models.ActionCloseIssue
  53. } else {
  54. actionType = models.ActionReopenIssue
  55. }
  56. }
  57. if err := mailer.MailParticipants(issue, doer, actionType); err != nil {
  58. log.Error("MailParticipants: %v", err)
  59. }
  60. }
  61. func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
  62. if err := mailer.MailParticipants(pr.Issue, pr.Issue.Poster, models.ActionCreatePullRequest); err != nil {
  63. log.Error("MailParticipants: %v", err)
  64. }
  65. }
  66. func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment) {
  67. var act models.ActionType
  68. if comment.Type == models.CommentTypeClose {
  69. act = models.ActionCloseIssue
  70. } else if comment.Type == models.CommentTypeReopen {
  71. act = models.ActionReopenIssue
  72. } else if comment.Type == models.CommentTypeComment {
  73. act = models.ActionCommentIssue
  74. }
  75. if err := mailer.MailParticipantsComment(comment, act, pr.Issue); err != nil {
  76. log.Error("MailParticipants: %v", err)
  77. }
  78. }