Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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/notification/action"
  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/repository"
  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, actionComment *models.Comment, closeOrReopen bool) {
  49. for _, notifier := range notifiers {
  50. notifier.NotifyIssueChangeStatus(doer, issue, actionComment, closeOrReopen)
  51. }
  52. }
  53. // NotifyMergePullRequest notifies merge pull request to notifiers
  54. func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
  55. for _, notifier := range notifiers {
  56. notifier.NotifyMergePullRequest(pr, doer)
  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. // NotifyPullRequestSynchronized notifies Synchronized pull request
  66. func NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
  67. for _, notifier := range notifiers {
  68. notifier.NotifyPullRequestSynchronized(doer, pr)
  69. }
  70. }
  71. // NotifyPullRequestReview notifies new pull request review
  72. func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) {
  73. for _, notifier := range notifiers {
  74. notifier.NotifyPullRequestReview(pr, review, comment)
  75. }
  76. }
  77. // NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed
  78. func NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
  79. for _, notifier := range notifiers {
  80. notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch)
  81. }
  82. }
  83. // NotifyPullRequestPushCommits notifies when push commits to pull request's head branch
  84. func NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) {
  85. for _, notifier := range notifiers {
  86. notifier.NotifyPullRequestPushCommits(doer, pr, comment)
  87. }
  88. }
  89. // NotifyUpdateComment notifies update comment to notifiers
  90. func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
  91. for _, notifier := range notifiers {
  92. notifier.NotifyUpdateComment(doer, c, oldContent)
  93. }
  94. }
  95. // NotifyDeleteComment notifies delete comment to notifiers
  96. func NotifyDeleteComment(doer *models.User, c *models.Comment) {
  97. for _, notifier := range notifiers {
  98. notifier.NotifyDeleteComment(doer, c)
  99. }
  100. }
  101. // NotifyNewRelease notifies new release to notifiers
  102. func NotifyNewRelease(rel *models.Release) {
  103. for _, notifier := range notifiers {
  104. notifier.NotifyNewRelease(rel)
  105. }
  106. }
  107. // NotifyUpdateRelease notifies update release to notifiers
  108. func NotifyUpdateRelease(doer *models.User, rel *models.Release) {
  109. for _, notifier := range notifiers {
  110. notifier.NotifyUpdateRelease(doer, rel)
  111. }
  112. }
  113. // NotifyDeleteRelease notifies delete release to notifiers
  114. func NotifyDeleteRelease(doer *models.User, rel *models.Release) {
  115. for _, notifier := range notifiers {
  116. notifier.NotifyDeleteRelease(doer, rel)
  117. }
  118. }
  119. // NotifyIssueChangeMilestone notifies change milestone to notifiers
  120. func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
  121. for _, notifier := range notifiers {
  122. notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
  123. }
  124. }
  125. // NotifyIssueChangeContent notifies change content to notifiers
  126. func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
  127. for _, notifier := range notifiers {
  128. notifier.NotifyIssueChangeContent(doer, issue, oldContent)
  129. }
  130. }
  131. // NotifyIssueChangeAssignee notifies change content to notifiers
  132. func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
  133. for _, notifier := range notifiers {
  134. notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment)
  135. }
  136. }
  137. // NotifyPullReviewRequest notifies Request Review change
  138. func NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
  139. for _, notifier := range notifiers {
  140. notifier.NotifyPullReviewRequest(doer, issue, reviewer, isRequest, comment)
  141. }
  142. }
  143. // NotifyIssueClearLabels notifies clear labels to notifiers
  144. func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
  145. for _, notifier := range notifiers {
  146. notifier.NotifyIssueClearLabels(doer, issue)
  147. }
  148. }
  149. // NotifyIssueChangeTitle notifies change title to notifiers
  150. func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
  151. for _, notifier := range notifiers {
  152. notifier.NotifyIssueChangeTitle(doer, issue, oldTitle)
  153. }
  154. }
  155. // NotifyIssueChangeLabels notifies change labels to notifiers
  156. func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
  157. addedLabels []*models.Label, removedLabels []*models.Label) {
  158. for _, notifier := range notifiers {
  159. notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
  160. }
  161. }
  162. // NotifyCreateRepository notifies create repository to notifiers
  163. func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  164. for _, notifier := range notifiers {
  165. notifier.NotifyCreateRepository(doer, u, repo)
  166. }
  167. }
  168. // NotifyMigrateRepository notifies create repository to notifiers
  169. func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  170. for _, notifier := range notifiers {
  171. notifier.NotifyMigrateRepository(doer, u, repo)
  172. }
  173. }
  174. // NotifyTransferRepository notifies create repository to notifiers
  175. func NotifyTransferRepository(doer *models.User, repo *models.Repository, newOwnerName string) {
  176. for _, notifier := range notifiers {
  177. notifier.NotifyTransferRepository(doer, repo, newOwnerName)
  178. }
  179. }
  180. // NotifyDeleteRepository notifies delete repository to notifiers
  181. func NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
  182. for _, notifier := range notifiers {
  183. notifier.NotifyDeleteRepository(doer, repo)
  184. }
  185. }
  186. // NotifyForkRepository notifies fork repository to notifiers
  187. func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
  188. for _, notifier := range notifiers {
  189. notifier.NotifyForkRepository(doer, oldRepo, repo)
  190. }
  191. }
  192. // NotifyRenameRepository notifies repository renamed
  193. func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
  194. for _, notifier := range notifiers {
  195. notifier.NotifyRenameRepository(doer, repo, oldName)
  196. }
  197. }
  198. // NotifyPushCommits notifies commits pushed to notifiers
  199. func NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  200. for _, notifier := range notifiers {
  201. notifier.NotifyPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits)
  202. }
  203. }
  204. // NotifyCreateRef notifies branch or tag creation to notifiers
  205. func NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  206. for _, notifier := range notifiers {
  207. notifier.NotifyCreateRef(pusher, repo, refType, refFullName)
  208. }
  209. }
  210. // NotifyDeleteRef notifies branch or tag deletion to notifiers
  211. func NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  212. for _, notifier := range notifiers {
  213. notifier.NotifyDeleteRef(pusher, repo, refType, refFullName)
  214. }
  215. }
  216. // NotifySyncPushCommits notifies commits pushed to notifiers
  217. func NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  218. for _, notifier := range notifiers {
  219. notifier.NotifySyncPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits)
  220. }
  221. }
  222. // NotifySyncCreateRef notifies branch or tag creation to notifiers
  223. func NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  224. for _, notifier := range notifiers {
  225. notifier.NotifySyncCreateRef(pusher, repo, refType, refFullName)
  226. }
  227. }
  228. // NotifySyncDeleteRef notifies branch or tag deletion to notifiers
  229. func NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  230. for _, notifier := range notifiers {
  231. notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName)
  232. }
  233. }