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

notification.go 5.7 kB

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