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.

notification.go 6.4KB

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