本站源代码
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.

186 satır
6.0KB

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