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.

notifier.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package actions
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/db"
  7. issues_model "code.gitea.io/gitea/models/issues"
  8. packages_model "code.gitea.io/gitea/models/packages"
  9. perm_model "code.gitea.io/gitea/models/perm"
  10. access_model "code.gitea.io/gitea/models/perm/access"
  11. repo_model "code.gitea.io/gitea/models/repo"
  12. user_model "code.gitea.io/gitea/models/user"
  13. "code.gitea.io/gitea/modules/git"
  14. "code.gitea.io/gitea/modules/log"
  15. "code.gitea.io/gitea/modules/notification/base"
  16. "code.gitea.io/gitea/modules/repository"
  17. "code.gitea.io/gitea/modules/setting"
  18. api "code.gitea.io/gitea/modules/structs"
  19. webhook_module "code.gitea.io/gitea/modules/webhook"
  20. "code.gitea.io/gitea/services/convert"
  21. )
  22. type actionsNotifier struct {
  23. base.NullNotifier
  24. }
  25. var _ base.Notifier = &actionsNotifier{}
  26. // NewNotifier create a new actionsNotifier notifier
  27. func NewNotifier() base.Notifier {
  28. return &actionsNotifier{}
  29. }
  30. // NotifyNewIssue notifies issue created event
  31. func (n *actionsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, _ []*user_model.User) {
  32. ctx = withMethod(ctx, "NotifyNewIssue")
  33. if err := issue.LoadRepo(ctx); err != nil {
  34. log.Error("issue.LoadRepo: %v", err)
  35. return
  36. }
  37. if err := issue.LoadPoster(ctx); err != nil {
  38. log.Error("issue.LoadPoster: %v", err)
  39. return
  40. }
  41. mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
  42. newNotifyInputFromIssue(issue, webhook_module.HookEventIssues).WithPayload(&api.IssuePayload{
  43. Action: api.HookIssueOpened,
  44. Index: issue.Index,
  45. Issue: convert.ToAPIIssue(ctx, issue),
  46. Repository: convert.ToRepo(ctx, issue.Repo, mode),
  47. Sender: convert.ToUser(ctx, issue.Poster, nil),
  48. }).Notify(withMethod(ctx, "NotifyNewIssue"))
  49. }
  50. // NotifyIssueChangeStatus notifies close or reopen issue to notifiers
  51. func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, _ *issues_model.Comment, isClosed bool) {
  52. ctx = withMethod(ctx, "NotifyIssueChangeStatus")
  53. mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
  54. if issue.IsPull {
  55. if err := issue.LoadPullRequest(ctx); err != nil {
  56. log.Error("LoadPullRequest: %v", err)
  57. return
  58. }
  59. // Merge pull request calls issue.changeStatus so we need to handle separately.
  60. apiPullRequest := &api.PullRequestPayload{
  61. Index: issue.Index,
  62. PullRequest: convert.ToAPIPullRequest(db.DefaultContext, issue.PullRequest, nil),
  63. Repository: convert.ToRepo(ctx, issue.Repo, mode),
  64. Sender: convert.ToUser(ctx, doer, nil),
  65. CommitID: commitID,
  66. }
  67. if isClosed {
  68. apiPullRequest.Action = api.HookIssueClosed
  69. } else {
  70. apiPullRequest.Action = api.HookIssueReOpened
  71. }
  72. newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequest).
  73. WithDoer(doer).
  74. WithPayload(apiPullRequest).
  75. Notify(ctx)
  76. return
  77. }
  78. apiIssue := &api.IssuePayload{
  79. Index: issue.Index,
  80. Issue: convert.ToAPIIssue(ctx, issue),
  81. Repository: convert.ToRepo(ctx, issue.Repo, mode),
  82. Sender: convert.ToUser(ctx, doer, nil),
  83. }
  84. if isClosed {
  85. apiIssue.Action = api.HookIssueClosed
  86. } else {
  87. apiIssue.Action = api.HookIssueReOpened
  88. }
  89. newNotifyInputFromIssue(issue, webhook_module.HookEventIssues).
  90. WithDoer(doer).
  91. WithPayload(apiIssue).
  92. Notify(ctx)
  93. }
  94. func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
  95. _, _ []*issues_model.Label,
  96. ) {
  97. ctx = withMethod(ctx, "NotifyIssueChangeLabels")
  98. var err error
  99. if err = issue.LoadRepo(ctx); err != nil {
  100. log.Error("LoadRepo: %v", err)
  101. return
  102. }
  103. if err = issue.LoadPoster(ctx); err != nil {
  104. log.Error("LoadPoster: %v", err)
  105. return
  106. }
  107. mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
  108. if issue.IsPull {
  109. if err = issue.LoadPullRequest(ctx); err != nil {
  110. log.Error("loadPullRequest: %v", err)
  111. return
  112. }
  113. if err = issue.PullRequest.LoadIssue(ctx); err != nil {
  114. log.Error("LoadIssue: %v", err)
  115. return
  116. }
  117. newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequestLabel).
  118. WithDoer(doer).
  119. WithPayload(&api.PullRequestPayload{
  120. Action: api.HookIssueLabelUpdated,
  121. Index: issue.Index,
  122. PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
  123. Repository: convert.ToRepo(ctx, issue.Repo, perm_model.AccessModeNone),
  124. Sender: convert.ToUser(ctx, doer, nil),
  125. }).
  126. Notify(ctx)
  127. return
  128. }
  129. newNotifyInputFromIssue(issue, webhook_module.HookEventIssueLabel).
  130. WithDoer(doer).
  131. WithPayload(&api.IssuePayload{
  132. Action: api.HookIssueLabelUpdated,
  133. Index: issue.Index,
  134. Issue: convert.ToAPIIssue(ctx, issue),
  135. Repository: convert.ToRepo(ctx, issue.Repo, mode),
  136. Sender: convert.ToUser(ctx, doer, nil),
  137. }).
  138. Notify(ctx)
  139. }
  140. // NotifyCreateIssueComment notifies comment on an issue to notifiers
  141. func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
  142. issue *issues_model.Issue, comment *issues_model.Comment, _ []*user_model.User,
  143. ) {
  144. ctx = withMethod(ctx, "NotifyCreateIssueComment")
  145. mode, _ := access_model.AccessLevel(ctx, doer, repo)
  146. if issue.IsPull {
  147. newNotifyInputFromIssue(issue, webhook_module.HookEventPullRequestComment).
  148. WithDoer(doer).
  149. WithPayload(&api.IssueCommentPayload{
  150. Action: api.HookIssueCommentCreated,
  151. Issue: convert.ToAPIIssue(ctx, issue),
  152. Comment: convert.ToComment(ctx, comment),
  153. Repository: convert.ToRepo(ctx, repo, mode),
  154. Sender: convert.ToUser(ctx, doer, nil),
  155. IsPull: true,
  156. }).
  157. Notify(ctx)
  158. return
  159. }
  160. newNotifyInputFromIssue(issue, webhook_module.HookEventIssueComment).
  161. WithDoer(doer).
  162. WithPayload(&api.IssueCommentPayload{
  163. Action: api.HookIssueCommentCreated,
  164. Issue: convert.ToAPIIssue(ctx, issue),
  165. Comment: convert.ToComment(ctx, comment),
  166. Repository: convert.ToRepo(ctx, repo, mode),
  167. Sender: convert.ToUser(ctx, doer, nil),
  168. IsPull: false,
  169. }).
  170. Notify(ctx)
  171. }
  172. func (n *actionsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, _ []*user_model.User) {
  173. ctx = withMethod(ctx, "NotifyNewPullRequest")
  174. if err := pull.LoadIssue(ctx); err != nil {
  175. log.Error("pull.LoadIssue: %v", err)
  176. return
  177. }
  178. if err := pull.Issue.LoadRepo(ctx); err != nil {
  179. log.Error("pull.Issue.LoadRepo: %v", err)
  180. return
  181. }
  182. if err := pull.Issue.LoadPoster(ctx); err != nil {
  183. log.Error("pull.Issue.LoadPoster: %v", err)
  184. return
  185. }
  186. mode, _ := access_model.AccessLevel(ctx, pull.Issue.Poster, pull.Issue.Repo)
  187. newNotifyInputFromIssue(pull.Issue, webhook_module.HookEventPullRequest).
  188. WithPayload(&api.PullRequestPayload{
  189. Action: api.HookIssueOpened,
  190. Index: pull.Issue.Index,
  191. PullRequest: convert.ToAPIPullRequest(ctx, pull, nil),
  192. Repository: convert.ToRepo(ctx, pull.Issue.Repo, mode),
  193. Sender: convert.ToUser(ctx, pull.Issue.Poster, nil),
  194. }).
  195. WithPullRequest(pull).
  196. Notify(ctx)
  197. }
  198. func (n *actionsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
  199. ctx = withMethod(ctx, "NotifyCreateRepository")
  200. newNotifyInput(repo, doer, webhook_module.HookEventRepository).WithPayload(&api.RepositoryPayload{
  201. Action: api.HookRepoCreated,
  202. Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  203. Organization: convert.ToUser(ctx, u, nil),
  204. Sender: convert.ToUser(ctx, doer, nil),
  205. }).Notify(ctx)
  206. }
  207. func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
  208. ctx = withMethod(ctx, "NotifyForkRepository")
  209. oldMode, _ := access_model.AccessLevel(ctx, doer, oldRepo)
  210. mode, _ := access_model.AccessLevel(ctx, doer, repo)
  211. // forked webhook
  212. newNotifyInput(oldRepo, doer, webhook_module.HookEventFork).WithPayload(&api.ForkPayload{
  213. Forkee: convert.ToRepo(ctx, oldRepo, oldMode),
  214. Repo: convert.ToRepo(ctx, repo, mode),
  215. Sender: convert.ToUser(ctx, doer, nil),
  216. }).Notify(ctx)
  217. u := repo.MustOwner(ctx)
  218. // Add to hook queue for created repo after session commit.
  219. if u.IsOrganization() {
  220. newNotifyInput(repo, doer, webhook_module.HookEventRepository).
  221. WithRef(oldRepo.DefaultBranch).
  222. WithPayload(&api.RepositoryPayload{
  223. Action: api.HookRepoCreated,
  224. Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  225. Organization: convert.ToUser(ctx, u, nil),
  226. Sender: convert.ToUser(ctx, doer, nil),
  227. }).Notify(ctx)
  228. }
  229. }
  230. func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) {
  231. ctx = withMethod(ctx, "NotifyPullRequestReview")
  232. var reviewHookType webhook_module.HookEventType
  233. switch review.Type {
  234. case issues_model.ReviewTypeApprove:
  235. reviewHookType = webhook_module.HookEventPullRequestReviewApproved
  236. case issues_model.ReviewTypeComment:
  237. reviewHookType = webhook_module.HookEventPullRequestReviewComment
  238. case issues_model.ReviewTypeReject:
  239. reviewHookType = webhook_module.HookEventPullRequestReviewRejected
  240. default:
  241. // unsupported review webhook type here
  242. log.Error("Unsupported review webhook type")
  243. return
  244. }
  245. if err := pr.LoadIssue(ctx); err != nil {
  246. log.Error("pr.LoadIssue: %v", err)
  247. return
  248. }
  249. mode, err := access_model.AccessLevel(ctx, review.Issue.Poster, review.Issue.Repo)
  250. if err != nil {
  251. log.Error("models.AccessLevel: %v", err)
  252. return
  253. }
  254. newNotifyInput(review.Issue.Repo, review.Reviewer, reviewHookType).
  255. WithRef(review.CommitID).
  256. WithPayload(&api.PullRequestPayload{
  257. Action: api.HookIssueReviewed,
  258. Index: review.Issue.Index,
  259. PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil),
  260. Repository: convert.ToRepo(ctx, review.Issue.Repo, mode),
  261. Sender: convert.ToUser(ctx, review.Reviewer, nil),
  262. Review: &api.ReviewPayload{
  263. Type: string(reviewHookType),
  264. Content: review.Content,
  265. },
  266. }).Notify(ctx)
  267. }
  268. func (*actionsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
  269. ctx = withMethod(ctx, "NotifyMergePullRequest")
  270. // Reload pull request information.
  271. if err := pr.LoadAttributes(ctx); err != nil {
  272. log.Error("LoadAttributes: %v", err)
  273. return
  274. }
  275. if err := pr.LoadIssue(ctx); err != nil {
  276. log.Error("LoadAttributes: %v", err)
  277. return
  278. }
  279. if err := pr.Issue.LoadRepo(db.DefaultContext); err != nil {
  280. log.Error("pr.Issue.LoadRepo: %v", err)
  281. return
  282. }
  283. mode, err := access_model.AccessLevel(ctx, doer, pr.Issue.Repo)
  284. if err != nil {
  285. log.Error("models.AccessLevel: %v", err)
  286. return
  287. }
  288. // Merge pull request calls issue.changeStatus so we need to handle separately.
  289. apiPullRequest := &api.PullRequestPayload{
  290. Index: pr.Issue.Index,
  291. PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil),
  292. Repository: convert.ToRepo(ctx, pr.Issue.Repo, mode),
  293. Sender: convert.ToUser(ctx, doer, nil),
  294. Action: api.HookIssueClosed,
  295. }
  296. newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequest).
  297. WithRef(pr.MergedCommitID).
  298. WithPayload(apiPullRequest).
  299. WithPullRequest(pr).
  300. Notify(ctx)
  301. }
  302. func (n *actionsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
  303. ctx = withMethod(ctx, "NotifyPushCommits")
  304. apiPusher := convert.ToUser(ctx, pusher, nil)
  305. apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
  306. if err != nil {
  307. log.Error("commits.ToAPIPayloadCommits failed: %v", err)
  308. return
  309. }
  310. newNotifyInput(repo, pusher, webhook_module.HookEventPush).
  311. WithRef(opts.RefFullName.String()).
  312. WithPayload(&api.PushPayload{
  313. Ref: opts.RefFullName.String(),
  314. Before: opts.OldCommitID,
  315. After: opts.NewCommitID,
  316. CompareURL: setting.AppURL + commits.CompareURL,
  317. Commits: apiCommits,
  318. HeadCommit: apiHeadCommit,
  319. Repo: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  320. Pusher: apiPusher,
  321. Sender: apiPusher,
  322. }).
  323. Notify(ctx)
  324. }
  325. func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
  326. ctx = withMethod(ctx, "NotifyCreateRef")
  327. apiPusher := convert.ToUser(ctx, pusher, nil)
  328. apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone)
  329. newNotifyInput(repo, pusher, webhook_module.HookEventCreate).
  330. WithRef(refFullName.ShortName()). // FIXME: should we use a full ref name
  331. WithPayload(&api.CreatePayload{
  332. Ref: refFullName.ShortName(),
  333. Sha: refID,
  334. RefType: refFullName.RefGroup(),
  335. Repo: apiRepo,
  336. Sender: apiPusher,
  337. }).
  338. Notify(ctx)
  339. }
  340. func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
  341. ctx = withMethod(ctx, "NotifyDeleteRef")
  342. apiPusher := convert.ToUser(ctx, pusher, nil)
  343. apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone)
  344. newNotifyInput(repo, pusher, webhook_module.HookEventDelete).
  345. WithRef(refFullName.ShortName()). // FIXME: should we use a full ref name
  346. WithPayload(&api.DeletePayload{
  347. Ref: refFullName.ShortName(),
  348. RefType: refFullName.RefGroup(),
  349. PusherType: api.PusherTypeUser,
  350. Repo: apiRepo,
  351. Sender: apiPusher,
  352. }).
  353. Notify(ctx)
  354. }
  355. func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
  356. ctx = withMethod(ctx, "NotifySyncPushCommits")
  357. apiPusher := convert.ToUser(ctx, pusher, nil)
  358. apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(db.DefaultContext, repo.RepoPath(), repo.HTMLURL())
  359. if err != nil {
  360. log.Error("commits.ToAPIPayloadCommits failed: %v", err)
  361. return
  362. }
  363. newNotifyInput(repo, pusher, webhook_module.HookEventPush).
  364. WithRef(opts.RefFullName.String()).
  365. WithPayload(&api.PushPayload{
  366. Ref: opts.RefFullName.String(),
  367. Before: opts.OldCommitID,
  368. After: opts.NewCommitID,
  369. CompareURL: setting.AppURL + commits.CompareURL,
  370. Commits: apiCommits,
  371. TotalCommits: commits.Len,
  372. HeadCommit: apiHeadCommit,
  373. Repo: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  374. Pusher: apiPusher,
  375. Sender: apiPusher,
  376. }).
  377. Notify(ctx)
  378. }
  379. func (n *actionsNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
  380. ctx = withMethod(ctx, "NotifySyncCreateRef")
  381. n.NotifyCreateRef(ctx, pusher, repo, refFullName, refID)
  382. }
  383. func (n *actionsNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
  384. ctx = withMethod(ctx, "NotifySyncDeleteRef")
  385. n.NotifyDeleteRef(ctx, pusher, repo, refFullName)
  386. }
  387. func (n *actionsNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
  388. ctx = withMethod(ctx, "NotifyNewRelease")
  389. notifyRelease(ctx, rel.Publisher, rel, api.HookReleasePublished)
  390. }
  391. func (n *actionsNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
  392. ctx = withMethod(ctx, "NotifyUpdateRelease")
  393. notifyRelease(ctx, doer, rel, api.HookReleaseUpdated)
  394. }
  395. func (n *actionsNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
  396. ctx = withMethod(ctx, "NotifyDeleteRelease")
  397. notifyRelease(ctx, doer, rel, api.HookReleaseDeleted)
  398. }
  399. func (n *actionsNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
  400. ctx = withMethod(ctx, "NotifyPackageCreate")
  401. notifyPackage(ctx, doer, pd, api.HookPackageCreated)
  402. }
  403. func (n *actionsNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
  404. ctx = withMethod(ctx, "NotifyPackageDelete")
  405. notifyPackage(ctx, doer, pd, api.HookPackageDeleted)
  406. }
  407. func (n *actionsNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
  408. ctx = withMethod(ctx, "NotifyAutoMergePullRequest")
  409. n.NotifyMergePullRequest(ctx, doer, pr)
  410. }
  411. func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
  412. ctx = withMethod(ctx, "NotifyPullRequestSynchronized")
  413. if err := pr.LoadIssue(ctx); err != nil {
  414. log.Error("LoadAttributes: %v", err)
  415. return
  416. }
  417. if err := pr.Issue.LoadRepo(db.DefaultContext); err != nil {
  418. log.Error("pr.Issue.LoadRepo: %v", err)
  419. return
  420. }
  421. newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequestSync).
  422. WithPayload(&api.PullRequestPayload{
  423. Action: api.HookIssueSynchronized,
  424. Index: pr.Issue.Index,
  425. PullRequest: convert.ToAPIPullRequest(ctx, pr, nil),
  426. Repository: convert.ToRepo(ctx, pr.Issue.Repo, perm_model.AccessModeNone),
  427. Sender: convert.ToUser(ctx, doer, nil),
  428. }).
  429. WithPullRequest(pr).
  430. Notify(ctx)
  431. }
  432. func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
  433. ctx = withMethod(ctx, "NotifyPullRequestChangeTargetBranch")
  434. if err := pr.LoadIssue(ctx); err != nil {
  435. log.Error("LoadAttributes: %v", err)
  436. return
  437. }
  438. if err := pr.Issue.LoadRepo(db.DefaultContext); err != nil {
  439. log.Error("pr.Issue.LoadRepo: %v", err)
  440. return
  441. }
  442. mode, _ := access_model.AccessLevel(ctx, pr.Issue.Poster, pr.Issue.Repo)
  443. newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequest).
  444. WithPayload(&api.PullRequestPayload{
  445. Action: api.HookIssueEdited,
  446. Index: pr.Issue.Index,
  447. Changes: &api.ChangesPayload{
  448. Ref: &api.ChangesFromPayload{
  449. From: oldBranch,
  450. },
  451. },
  452. PullRequest: convert.ToAPIPullRequest(ctx, pr, nil),
  453. Repository: convert.ToRepo(ctx, pr.Issue.Repo, mode),
  454. Sender: convert.ToUser(ctx, doer, nil),
  455. }).
  456. WithPullRequest(pr).
  457. Notify(ctx)
  458. }
  459. func (n *actionsNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
  460. ctx = withMethod(ctx, "NotifyNewWikiPage")
  461. newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
  462. Action: api.HookWikiCreated,
  463. Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  464. Sender: convert.ToUser(ctx, doer, nil),
  465. Page: page,
  466. Comment: comment,
  467. }).Notify(ctx)
  468. }
  469. func (n *actionsNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
  470. ctx = withMethod(ctx, "NotifyEditWikiPage")
  471. newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
  472. Action: api.HookWikiEdited,
  473. Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  474. Sender: convert.ToUser(ctx, doer, nil),
  475. Page: page,
  476. Comment: comment,
  477. }).Notify(ctx)
  478. }
  479. func (n *actionsNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
  480. ctx = withMethod(ctx, "NotifyDeleteWikiPage")
  481. newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
  482. Action: api.HookWikiDeleted,
  483. Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  484. Sender: convert.ToUser(ctx, doer, nil),
  485. Page: page,
  486. }).Notify(ctx)
  487. }