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
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>
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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/ui"
  13. "code.gitea.io/gitea/modules/notification/webhook"
  14. "code.gitea.io/gitea/modules/repository"
  15. "code.gitea.io/gitea/modules/setting"
  16. )
  17. var (
  18. notifiers []base.Notifier
  19. )
  20. // RegisterNotifier providers method to receive notify messages
  21. func RegisterNotifier(notifier base.Notifier) {
  22. go notifier.Run()
  23. notifiers = append(notifiers, notifier)
  24. }
  25. // NewContext registers notification handlers
  26. func NewContext() {
  27. RegisterNotifier(ui.NewNotifier())
  28. if setting.Service.EnableNotifyMail {
  29. RegisterNotifier(mail.NewNotifier())
  30. }
  31. RegisterNotifier(indexer.NewNotifier())
  32. RegisterNotifier(webhook.NewNotifier())
  33. RegisterNotifier(action.NewNotifier())
  34. }
  35. // NotifyUploadAttachment notifies attachment upload message to notifiers
  36. func NotifyOtherTask(doer *models.User, repo *models.Repository, id string, name string, optype models.ActionType) {
  37. for _, notifier := range notifiers {
  38. notifier.NotifyOtherTask(doer, repo, id, name, optype)
  39. }
  40. }
  41. // NotifyCreateIssueComment notifies issue comment related message to notifiers
  42. func NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  43. issue *models.Issue, comment *models.Comment) {
  44. for _, notifier := range notifiers {
  45. notifier.NotifyCreateIssueComment(doer, repo, issue, comment)
  46. }
  47. }
  48. // NotifyNewIssue notifies new issue to notifiers
  49. func NotifyNewIssue(issue *models.Issue) {
  50. for _, notifier := range notifiers {
  51. notifier.NotifyNewIssue(issue)
  52. }
  53. }
  54. // NotifyIssueChangeStatus notifies close or reopen issue to notifiers
  55. func NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) {
  56. for _, notifier := range notifiers {
  57. notifier.NotifyIssueChangeStatus(doer, issue, actionComment, closeOrReopen)
  58. }
  59. }
  60. // NotifyMergePullRequest notifies merge pull request to notifiers
  61. func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
  62. for _, notifier := range notifiers {
  63. notifier.NotifyMergePullRequest(pr, doer)
  64. }
  65. }
  66. // NotifyNewPullRequest notifies new pull request to notifiers
  67. func NotifyNewPullRequest(pr *models.PullRequest) {
  68. for _, notifier := range notifiers {
  69. notifier.NotifyNewPullRequest(pr)
  70. }
  71. }
  72. // NotifyPullRequestSynchronized notifies Synchronized pull request
  73. func NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {
  74. for _, notifier := range notifiers {
  75. notifier.NotifyPullRequestSynchronized(doer, pr)
  76. }
  77. }
  78. // NotifyPullRequestReview notifies new pull request review
  79. func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment) {
  80. for _, notifier := range notifiers {
  81. notifier.NotifyPullRequestReview(pr, review, comment)
  82. }
  83. }
  84. // NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed
  85. func NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) {
  86. for _, notifier := range notifiers {
  87. notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch)
  88. }
  89. }
  90. // NotifyUpdateComment notifies update comment to notifiers
  91. func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
  92. for _, notifier := range notifiers {
  93. notifier.NotifyUpdateComment(doer, c, oldContent)
  94. }
  95. }
  96. // NotifyDeleteComment notifies delete comment to notifiers
  97. func NotifyDeleteComment(doer *models.User, c *models.Comment) {
  98. for _, notifier := range notifiers {
  99. notifier.NotifyDeleteComment(doer, c)
  100. }
  101. }
  102. // NotifyNewRelease notifies new release to notifiers
  103. func NotifyNewRelease(rel *models.Release) {
  104. for _, notifier := range notifiers {
  105. notifier.NotifyNewRelease(rel)
  106. }
  107. }
  108. // NotifyUpdateRelease notifies update release to notifiers
  109. func NotifyUpdateRelease(doer *models.User, rel *models.Release) {
  110. for _, notifier := range notifiers {
  111. notifier.NotifyUpdateRelease(doer, rel)
  112. }
  113. }
  114. // NotifyDeleteRelease notifies delete release to notifiers
  115. func NotifyDeleteRelease(doer *models.User, rel *models.Release) {
  116. for _, notifier := range notifiers {
  117. notifier.NotifyDeleteRelease(doer, rel)
  118. }
  119. }
  120. // NotifyIssueChangeMilestone notifies change milestone to notifiers
  121. func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
  122. for _, notifier := range notifiers {
  123. notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
  124. }
  125. }
  126. // NotifyIssueChangeContent notifies change content to notifiers
  127. func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
  128. for _, notifier := range notifiers {
  129. notifier.NotifyIssueChangeContent(doer, issue, oldContent)
  130. }
  131. }
  132. // NotifyIssueChangeAssignee notifies change content to notifiers
  133. func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) {
  134. for _, notifier := range notifiers {
  135. notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment)
  136. }
  137. }
  138. // NotifyPullReviewRequest notifies Request Review change
  139. func NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) {
  140. for _, notifier := range notifiers {
  141. notifier.NotifyPullReviewRequest(doer, issue, reviewer, isRequest, comment)
  142. }
  143. }
  144. // NotifyIssueClearLabels notifies clear labels to notifiers
  145. func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
  146. for _, notifier := range notifiers {
  147. notifier.NotifyIssueClearLabels(doer, issue)
  148. }
  149. }
  150. // NotifyIssueChangeTitle notifies change title to notifiers
  151. func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
  152. for _, notifier := range notifiers {
  153. notifier.NotifyIssueChangeTitle(doer, issue, oldTitle)
  154. }
  155. }
  156. // NotifyIssueChangeLabels notifies change labels to notifiers
  157. func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
  158. addedLabels []*models.Label, removedLabels []*models.Label) {
  159. for _, notifier := range notifiers {
  160. notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
  161. }
  162. }
  163. // NotifyCreateRepository notifies create repository to notifiers
  164. func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  165. for _, notifier := range notifiers {
  166. notifier.NotifyCreateRepository(doer, u, repo)
  167. }
  168. }
  169. // NotifyMigrateRepository notifies create repository to notifiers
  170. func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  171. for _, notifier := range notifiers {
  172. notifier.NotifyMigrateRepository(doer, u, repo)
  173. }
  174. }
  175. // NotifyTransferRepository notifies create repository to notifiers
  176. func NotifyTransferRepository(doer *models.User, repo *models.Repository, newOwnerName string) {
  177. for _, notifier := range notifiers {
  178. notifier.NotifyTransferRepository(doer, repo, newOwnerName)
  179. }
  180. }
  181. // NotifyDeleteRepository notifies delete repository to notifiers
  182. func NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
  183. for _, notifier := range notifiers {
  184. notifier.NotifyDeleteRepository(doer, repo)
  185. }
  186. }
  187. // NotifyForkRepository notifies fork repository to notifiers
  188. func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
  189. for _, notifier := range notifiers {
  190. notifier.NotifyForkRepository(doer, oldRepo, repo)
  191. }
  192. }
  193. // NotifyRenameRepository notifies repository renamed
  194. func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
  195. for _, notifier := range notifiers {
  196. notifier.NotifyRenameRepository(doer, repo, oldName)
  197. }
  198. }
  199. // NotifyPushCommits notifies commits pushed to notifiers
  200. func NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  201. for _, notifier := range notifiers {
  202. notifier.NotifyPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits)
  203. }
  204. }
  205. // NotifyCreateRef notifies branch or tag creation to notifiers
  206. func NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  207. for _, notifier := range notifiers {
  208. notifier.NotifyCreateRef(pusher, repo, refType, refFullName)
  209. }
  210. }
  211. // NotifyDeleteRef notifies branch or tag deletion to notifiers
  212. func NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  213. for _, notifier := range notifiers {
  214. notifier.NotifyDeleteRef(pusher, repo, refType, refFullName)
  215. }
  216. }
  217. // NotifySyncPushCommits notifies commits pushed to notifiers
  218. func NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) {
  219. for _, notifier := range notifiers {
  220. notifier.NotifySyncPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits)
  221. }
  222. }
  223. // NotifySyncCreateRef notifies branch or tag creation to notifiers
  224. func NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  225. for _, notifier := range notifiers {
  226. notifier.NotifySyncCreateRef(pusher, repo, refType, refFullName)
  227. }
  228. }
  229. // NotifySyncDeleteRef notifies branch or tag deletion to notifiers
  230. func NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
  231. for _, notifier := range notifiers {
  232. notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName)
  233. }
  234. }
  235. // NotifyWechatBind notifies wechat bind
  236. func NotifyWechatBind(user *models.User, wechatOpenId string) {
  237. for _, notifier := range notifiers {
  238. notifier.NotifyWechatBind(user, wechatOpenId)
  239. }
  240. }
  241. // NotifyDatasetRecommend
  242. func NotifyDatasetRecommend(optUser *models.User, dataset *models.Dataset, action string) {
  243. for _, notifier := range notifiers {
  244. notifier.NotifyDatasetRecommend(optUser, dataset, action)
  245. }
  246. }
  247. // NotifyDatasetRecommend
  248. func NotifyCreateImage(doer *models.User, image models.Image) {
  249. for _, notifier := range notifiers {
  250. notifier.NotifyCreateImage(doer, image)
  251. }
  252. }
  253. // NotifyDatasetRecommend
  254. func NotifyImageRecommend(optUser *models.User, imageId int64, action string) {
  255. for _, notifier := range notifiers {
  256. notifier.NotifyImageRecommend(optUser, imageId, action)
  257. }
  258. }
  259. // NotifyDatasetRecommend
  260. func NotifyChangeUserAvatar(user *models.User, form auth.AvatarForm) {
  261. for _, notifier := range notifiers {
  262. notifier.NotifyChangeUserAvatar(user, form)
  263. }
  264. }