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.

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