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 11 kB

3 years ago
3 years ago
3 years ago
Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Make sure to check all commits Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Print error messages for user as error flash message Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change order of branch select fields Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes duplicate check Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use ctx.Tr for translations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Recompile JS Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use correct translation namespace Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove redundant if condition Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Completes comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Revert changes to go.mod Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Directly use createComment method Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Remove variable declaration Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds blank line Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Test patch before persisting new target branch Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update patch before testing (not working) Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unneeded check for base name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update PR in one transaction Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment and simplify return Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjust CreateComment method call Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
6 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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/auth"
  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/reward"
  13. "code.gitea.io/gitea/modules/notification/ui"
  14. "code.gitea.io/gitea/modules/notification/webhook"
  15. wechatNotifier "code.gitea.io/gitea/modules/notification/wechat"
  16. "code.gitea.io/gitea/modules/repository"
  17. "code.gitea.io/gitea/modules/setting"
  18. )
  19. var (
  20. notifiers []base.Notifier
  21. )
  22. // RegisterNotifier providers method to receive notify messages
  23. func RegisterNotifier(notifier base.Notifier) {
  24. go notifier.Run()
  25. notifiers = append(notifiers, notifier)
  26. }
  27. // NewContext registers notification handlers
  28. func NewContext() {
  29. RegisterNotifier(ui.NewNotifier())
  30. if setting.Service.EnableNotifyMail {
  31. RegisterNotifier(mail.NewNotifier())
  32. }
  33. RegisterNotifier(indexer.NewNotifier())
  34. RegisterNotifier(webhook.NewNotifier())
  35. RegisterNotifier(action.NewNotifier())
  36. RegisterNotifier(wechatNotifier.NewNotifier())
  37. RegisterNotifier(reward.NewNotifier())
  38. }
  39. // NotifyUploadAttachment notifies attachment upload message to notifiers
  40. func NotifyOtherTask(doer *models.User, repo *models.Repository, id string, name string, optype models.ActionType) {
  41. for _, notifier := range notifiers {
  42. notifier.NotifyOtherTask(doer, repo, id, name, optype)
  43. }
  44. }
  45. // NotifyCreateIssueComment notifies issue comment related message to notifiers
  46. func NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  47. issue *models.Issue, comment *models.Comment) {
  48. for _, notifier := range notifiers {
  49. notifier.NotifyCreateIssueComment(doer, repo, issue, comment)
  50. }
  51. }
  52. // NotifyNewIssue notifies new issue to notifiers
  53. func NotifyNewIssue(issue *models.Issue) {
  54. for _, notifier := range notifiers {
  55. notifier.NotifyNewIssue(issue)
  56. }
  57. }
  58. // NotifyIssueChangeStatus notifies close or reopen issue to notifiers
  59. func NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) {
  60. for _, notifier := range notifiers {
  61. notifier.NotifyIssueChangeStatus(doer, issue, actionComment, closeOrReopen)
  62. }
  63. }
  64. // NotifyMergePullRequest notifies merge pull request to notifiers
  65. func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
  66. for _, notifier := range notifiers {
  67. notifier.NotifyMergePullRequest(pr, doer)
  68. }
  69. }
  70. // NotifyNewPullRequest notifies new pull request to notifiers
  71. func NotifyNewPullRequest(pr *models.PullRequest) {
  72. for _, notifier := range notifiers {
  73. notifier.NotifyNewPullRequest(pr)
  74. }
  75. }
  76. // NotifyPullRequestSynchronized notifies Synchronized pull request
  77. func NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
  78. for _, notifier := range notifiers {
  79. notifier.NotifyPullRequestSynchronized(doer, pr)
  80. }
  81. }
  82. // NotifyPullRequestReview notifies new pull request review
  83. func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) {
  84. for _, notifier := range notifiers {
  85. notifier.NotifyPullRequestReview(pr, review, comment)
  86. }
  87. }
  88. // NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed
  89. func NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
  90. for _, notifier := range notifiers {
  91. notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch)
  92. }
  93. }
  94. // NotifyUpdateComment notifies update comment to notifiers
  95. func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
  96. for _, notifier := range notifiers {
  97. notifier.NotifyUpdateComment(doer, c, oldContent)
  98. }
  99. }
  100. // NotifyDeleteComment notifies delete comment to notifiers
  101. func NotifyDeleteComment(doer *models.User, c *models.Comment) {
  102. for _, notifier := range notifiers {
  103. notifier.NotifyDeleteComment(doer, c)
  104. }
  105. }
  106. // NotifyNewRelease notifies new release to notifiers
  107. func NotifyNewRelease(rel *models.Release) {
  108. for _, notifier := range notifiers {
  109. notifier.NotifyNewRelease(rel)
  110. }
  111. }
  112. // NotifyUpdateRelease notifies update release to notifiers
  113. func NotifyUpdateRelease(doer *models.User, rel *models.Release) {
  114. for _, notifier := range notifiers {
  115. notifier.NotifyUpdateRelease(doer, rel)
  116. }
  117. }
  118. // NotifyDeleteRelease notifies delete release to notifiers
  119. func NotifyDeleteRelease(doer *models.User, rel *models.Release) {
  120. for _, notifier := range notifiers {
  121. notifier.NotifyDeleteRelease(doer, rel)
  122. }
  123. }
  124. // NotifyIssueChangeMilestone notifies change milestone to notifiers
  125. func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
  126. for _, notifier := range notifiers {
  127. notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
  128. }
  129. }
  130. // NotifyIssueChangeContent notifies change content to notifiers
  131. func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
  132. for _, notifier := range notifiers {
  133. notifier.NotifyIssueChangeContent(doer, issue, oldContent)
  134. }
  135. }
  136. // NotifyIssueChangeAssignee notifies change content to notifiers
  137. func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
  138. for _, notifier := range notifiers {
  139. notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment)
  140. }
  141. }
  142. // NotifyPullReviewRequest notifies Request Review change
  143. func NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
  144. for _, notifier := range notifiers {
  145. notifier.NotifyPullReviewRequest(doer, issue, reviewer, isRequest, comment)
  146. }
  147. }
  148. // NotifyIssueClearLabels notifies clear labels to notifiers
  149. func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
  150. for _, notifier := range notifiers {
  151. notifier.NotifyIssueClearLabels(doer, issue)
  152. }
  153. }
  154. // NotifyIssueChangeTitle notifies change title to notifiers
  155. func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
  156. for _, notifier := range notifiers {
  157. notifier.NotifyIssueChangeTitle(doer, issue, oldTitle)
  158. }
  159. }
  160. // NotifyIssueChangeLabels notifies change labels to notifiers
  161. func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
  162. addedLabels []*models.Label, removedLabels []*models.Label) {
  163. for _, notifier := range notifiers {
  164. notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
  165. }
  166. }
  167. // NotifyCreateRepository notifies create repository to notifiers
  168. func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  169. for _, notifier := range notifiers {
  170. notifier.NotifyCreateRepository(doer, u, repo)
  171. }
  172. }
  173. // NotifyMigrateRepository notifies create repository to notifiers
  174. func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  175. for _, notifier := range notifiers {
  176. notifier.NotifyMigrateRepository(doer, u, repo)
  177. }
  178. }
  179. // NotifyTransferRepository notifies create repository to notifiers
  180. func NotifyTransferRepository(doer *models.User, repo *models.Repository, newOwnerName string) {
  181. for _, notifier := range notifiers {
  182. notifier.NotifyTransferRepository(doer, repo, newOwnerName)
  183. }
  184. }
  185. // NotifyDeleteRepository notifies delete repository to notifiers
  186. func NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
  187. for _, notifier := range notifiers {
  188. notifier.NotifyDeleteRepository(doer, repo)
  189. }
  190. }
  191. // NotifyForkRepository notifies fork repository to notifiers
  192. func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
  193. for _, notifier := range notifiers {
  194. notifier.NotifyForkRepository(doer, oldRepo, repo)
  195. }
  196. }
  197. // NotifyRenameRepository notifies repository renamed
  198. func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
  199. for _, notifier := range notifiers {
  200. notifier.NotifyRenameRepository(doer, repo, oldName)
  201. }
  202. }
  203. // NotifyPushCommits notifies commits pushed to notifiers
  204. func NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  205. for _, notifier := range notifiers {
  206. notifier.NotifyPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits)
  207. }
  208. }
  209. // NotifyCreateRef notifies branch or tag creation to notifiers
  210. func NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  211. for _, notifier := range notifiers {
  212. notifier.NotifyCreateRef(pusher, repo, refType, refFullName)
  213. }
  214. }
  215. // NotifyDeleteRef notifies branch or tag deletion to notifiers
  216. func NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  217. for _, notifier := range notifiers {
  218. notifier.NotifyDeleteRef(pusher, repo, refType, refFullName)
  219. }
  220. }
  221. // NotifySyncPushCommits notifies commits pushed to notifiers
  222. func NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  223. for _, notifier := range notifiers {
  224. notifier.NotifySyncPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits)
  225. }
  226. }
  227. // NotifySyncCreateRef notifies branch or tag creation to notifiers
  228. func NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  229. for _, notifier := range notifiers {
  230. notifier.NotifySyncCreateRef(pusher, repo, refType, refFullName)
  231. }
  232. }
  233. // NotifySyncDeleteRef notifies branch or tag deletion to notifiers
  234. func NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  235. for _, notifier := range notifiers {
  236. notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName)
  237. }
  238. }
  239. // NotifyWechatBind notifies wechat bind
  240. func NotifyWechatBind(user *models.User, wechatOpenId string) {
  241. for _, notifier := range notifiers {
  242. notifier.NotifyWechatBind(user, wechatOpenId)
  243. }
  244. }
  245. // NotifyDatasetRecommend
  246. func NotifyDatasetRecommend(optUser *models.User, dataset *models.Dataset, action string) {
  247. for _, notifier := range notifiers {
  248. notifier.NotifyDatasetRecommend(optUser, dataset, action)
  249. }
  250. }
  251. // NotifyDatasetRecommend
  252. func NotifyCreateImage(doer *models.User, image models.Image) {
  253. for _, notifier := range notifiers {
  254. notifier.NotifyCreateImage(doer, image)
  255. }
  256. }
  257. // NotifyDatasetRecommend
  258. func NotifyImageRecommend(optUser *models.User, image *models.Image, action string) {
  259. for _, notifier := range notifiers {
  260. notifier.NotifyImageRecommend(optUser, image, action)
  261. }
  262. }
  263. // NotifyDatasetRecommend
  264. func NotifyChangeUserAvatar(user *models.User, form auth.AvatarForm) {
  265. for _, notifier := range notifiers {
  266. notifier.NotifyChangeUserAvatar(user, form)
  267. }
  268. }
  269. // NotifyChangeCloudbrainStatus
  270. func NotifyChangeCloudbrainStatus(cloudbrain *models.Cloudbrain, oldStatus string) {
  271. for _, notifier := range notifiers {
  272. notifier.NotifyChangeCloudbrainStatus(cloudbrain, oldStatus)
  273. }
  274. }