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.

179 lines
5.7 KiB

  1. // Copyright 2018 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 notification
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/git"
  8. "code.gitea.io/gitea/modules/notification/base"
  9. "code.gitea.io/gitea/modules/notification/indexer"
  10. "code.gitea.io/gitea/modules/notification/mail"
  11. "code.gitea.io/gitea/modules/notification/ui"
  12. )
  13. var (
  14. notifiers []base.Notifier
  15. )
  16. // RegisterNotifier providers method to receive notify messages
  17. func RegisterNotifier(notifier base.Notifier) {
  18. go notifier.Run()
  19. notifiers = append(notifiers, notifier)
  20. }
  21. func init() {
  22. RegisterNotifier(ui.NewNotifier())
  23. RegisterNotifier(mail.NewNotifier())
  24. RegisterNotifier(indexer.NewNotifier())
  25. }
  26. // NotifyCreateIssueComment notifies issue comment related message to notifiers
  27. func NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  28. issue *models.Issue, comment *models.Comment) {
  29. for _, notifier := range notifiers {
  30. notifier.NotifyCreateIssueComment(doer, repo, issue, comment)
  31. }
  32. }
  33. // NotifyNewIssue notifies new issue to notifiers
  34. func NotifyNewIssue(issue *models.Issue) {
  35. for _, notifier := range notifiers {
  36. notifier.NotifyNewIssue(issue)
  37. }
  38. }
  39. // NotifyIssueChangeStatus notifies close or reopen issue to notifiers
  40. func NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, closeOrReopen bool) {
  41. for _, notifier := range notifiers {
  42. notifier.NotifyIssueChangeStatus(doer, issue, closeOrReopen)
  43. }
  44. }
  45. // NotifyMergePullRequest notifies merge pull request to notifiers
  46. func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) {
  47. for _, notifier := range notifiers {
  48. notifier.NotifyMergePullRequest(pr, doer, baseGitRepo)
  49. }
  50. }
  51. // NotifyNewPullRequest notifies new pull request to notifiers
  52. func NotifyNewPullRequest(pr *models.PullRequest) {
  53. for _, notifier := range notifiers {
  54. notifier.NotifyNewPullRequest(pr)
  55. }
  56. }
  57. // NotifyPullRequestReview notifies new pull request review
  58. func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) {
  59. for _, notifier := range notifiers {
  60. notifier.NotifyPullRequestReview(pr, review, comment)
  61. }
  62. }
  63. // NotifyUpdateComment notifies update comment to notifiers
  64. func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
  65. for _, notifier := range notifiers {
  66. notifier.NotifyUpdateComment(doer, c, oldContent)
  67. }
  68. }
  69. // NotifyDeleteComment notifies delete comment to notifiers
  70. func NotifyDeleteComment(doer *models.User, c *models.Comment) {
  71. for _, notifier := range notifiers {
  72. notifier.NotifyDeleteComment(doer, c)
  73. }
  74. }
  75. // NotifyDeleteRepository notifies delete repository to notifiers
  76. func NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
  77. for _, notifier := range notifiers {
  78. notifier.NotifyDeleteRepository(doer, repo)
  79. }
  80. }
  81. // NotifyForkRepository notifies fork repository to notifiers
  82. func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
  83. for _, notifier := range notifiers {
  84. notifier.NotifyForkRepository(doer, oldRepo, repo)
  85. }
  86. }
  87. // NotifyNewRelease notifies new release to notifiers
  88. func NotifyNewRelease(rel *models.Release) {
  89. for _, notifier := range notifiers {
  90. notifier.NotifyNewRelease(rel)
  91. }
  92. }
  93. // NotifyUpdateRelease notifies update release to notifiers
  94. func NotifyUpdateRelease(doer *models.User, rel *models.Release) {
  95. for _, notifier := range notifiers {
  96. notifier.NotifyUpdateRelease(doer, rel)
  97. }
  98. }
  99. // NotifyDeleteRelease notifies delete release to notifiers
  100. func NotifyDeleteRelease(doer *models.User, rel *models.Release) {
  101. for _, notifier := range notifiers {
  102. notifier.NotifyDeleteRelease(doer, rel)
  103. }
  104. }
  105. // NotifyIssueChangeMilestone notifies change milestone to notifiers
  106. func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) {
  107. for _, notifier := range notifiers {
  108. notifier.NotifyIssueChangeMilestone(doer, issue)
  109. }
  110. }
  111. // NotifyIssueChangeContent notifies change content to notifiers
  112. func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
  113. for _, notifier := range notifiers {
  114. notifier.NotifyIssueChangeContent(doer, issue, oldContent)
  115. }
  116. }
  117. // NotifyIssueChangeAssignee notifies change content to notifiers
  118. func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) {
  119. for _, notifier := range notifiers {
  120. notifier.NotifyIssueChangeAssignee(doer, issue, removed)
  121. }
  122. }
  123. // NotifyIssueClearLabels notifies clear labels to notifiers
  124. func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
  125. for _, notifier := range notifiers {
  126. notifier.NotifyIssueClearLabels(doer, issue)
  127. }
  128. }
  129. // NotifyIssueChangeTitle notifies change title to notifiers
  130. func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
  131. for _, notifier := range notifiers {
  132. notifier.NotifyIssueChangeTitle(doer, issue, oldTitle)
  133. }
  134. }
  135. // NotifyIssueChangeLabels notifies change labels to notifiers
  136. func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
  137. addedLabels []*models.Label, removedLabels []*models.Label) {
  138. for _, notifier := range notifiers {
  139. notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
  140. }
  141. }
  142. // NotifyCreateRepository notifies create repository to notifiers
  143. func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  144. for _, notifier := range notifiers {
  145. notifier.NotifyCreateRepository(doer, u, repo)
  146. }
  147. }
  148. // NotifyMigrateRepository notifies create repository to notifiers
  149. func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  150. for _, notifier := range notifiers {
  151. notifier.NotifyMigrateRepository(doer, u, repo)
  152. }
  153. }