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 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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(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(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(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(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(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(comment),
  153. Repository: convert.ToRepo(ctx, repo, mode),
  154. Sender: convert.ToUser(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(comment),
  166. Repository: convert.ToRepo(ctx, repo, mode),
  167. Sender: convert.ToUser(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(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(u, nil),
  204. Sender: convert.ToUser(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(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(u, nil),
  226. Sender: convert.ToUser(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.HookEventPullRequestComment
  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(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(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(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).
  312. WithPayload(&api.PushPayload{
  313. Ref: opts.RefFullName,
  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, refType, refFullName, refID string) {
  326. ctx = withMethod(ctx, "NotifyCreateRef")
  327. apiPusher := convert.ToUser(pusher, nil)
  328. apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone)
  329. refName := git.RefEndName(refFullName)
  330. newNotifyInput(repo, pusher, webhook_module.HookEventCreate).
  331. WithRef(refName).
  332. WithPayload(&api.CreatePayload{
  333. Ref: refName,
  334. Sha: refID,
  335. RefType: refType,
  336. Repo: apiRepo,
  337. Sender: apiPusher,
  338. }).
  339. Notify(ctx)
  340. }
  341. func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
  342. ctx = withMethod(ctx, "NotifyDeleteRef")
  343. apiPusher := convert.ToUser(pusher, nil)
  344. apiRepo := convert.ToRepo(ctx, repo, perm_model.AccessModeNone)
  345. refName := git.RefEndName(refFullName)
  346. newNotifyInput(repo, pusher, webhook_module.HookEventDelete).
  347. WithRef(refName).
  348. WithPayload(&api.DeletePayload{
  349. Ref: refName,
  350. RefType: refType,
  351. PusherType: api.PusherTypeUser,
  352. Repo: apiRepo,
  353. Sender: apiPusher,
  354. }).
  355. Notify(ctx)
  356. }
  357. func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
  358. ctx = withMethod(ctx, "NotifySyncPushCommits")
  359. apiPusher := convert.ToUser(pusher, nil)
  360. apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(db.DefaultContext, repo.RepoPath(), repo.HTMLURL())
  361. if err != nil {
  362. log.Error("commits.ToAPIPayloadCommits failed: %v", err)
  363. return
  364. }
  365. newNotifyInput(repo, pusher, webhook_module.HookEventPush).
  366. WithRef(opts.RefFullName).
  367. WithPayload(&api.PushPayload{
  368. Ref: opts.RefFullName,
  369. Before: opts.OldCommitID,
  370. After: opts.NewCommitID,
  371. CompareURL: setting.AppURL + commits.CompareURL,
  372. Commits: apiCommits,
  373. TotalCommits: commits.Len,
  374. HeadCommit: apiHeadCommit,
  375. Repo: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
  376. Pusher: apiPusher,
  377. Sender: apiPusher,
  378. }).
  379. Notify(ctx)
  380. }
  381. func (n *actionsNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
  382. ctx = withMethod(ctx, "NotifySyncCreateRef")
  383. n.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID)
  384. }
  385. func (n *actionsNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
  386. ctx = withMethod(ctx, "NotifySyncDeleteRef")
  387. n.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName)
  388. }
  389. func (n *actionsNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
  390. ctx = withMethod(ctx, "NotifyNewRelease")
  391. notifyRelease(ctx, rel.Publisher, rel, rel.Sha1, api.HookReleasePublished)
  392. }
  393. func (n *actionsNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
  394. ctx = withMethod(ctx, "NotifyUpdateRelease")
  395. notifyRelease(ctx, doer, rel, rel.Sha1, api.HookReleaseUpdated)
  396. }
  397. func (n *actionsNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
  398. ctx = withMethod(ctx, "NotifyDeleteRelease")
  399. notifyRelease(ctx, doer, rel, rel.Sha1, api.HookReleaseDeleted)
  400. }
  401. func (n *actionsNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
  402. ctx = withMethod(ctx, "NotifyPackageCreate")
  403. notifyPackage(ctx, doer, pd, api.HookPackageCreated)
  404. }
  405. func (n *actionsNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
  406. ctx = withMethod(ctx, "NotifyPackageDelete")
  407. notifyPackage(ctx, doer, pd, api.HookPackageDeleted)
  408. }
  409. func (n *actionsNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
  410. ctx = withMethod(ctx, "NotifyAutoMergePullRequest")
  411. n.NotifyMergePullRequest(ctx, doer, pr)
  412. }
  413. func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
  414. ctx = withMethod(ctx, "NotifyPullRequestSynchronized")
  415. if err := pr.LoadIssue(ctx); err != nil {
  416. log.Error("LoadAttributes: %v", err)
  417. return
  418. }
  419. if err := pr.Issue.LoadRepo(db.DefaultContext); err != nil {
  420. log.Error("pr.Issue.LoadRepo: %v", err)
  421. return
  422. }
  423. newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequestSync).
  424. WithPayload(&api.PullRequestPayload{
  425. Action: api.HookIssueSynchronized,
  426. Index: pr.Issue.Index,
  427. PullRequest: convert.ToAPIPullRequest(ctx, pr, nil),
  428. Repository: convert.ToRepo(ctx, pr.Issue.Repo, perm_model.AccessModeNone),
  429. Sender: convert.ToUser(doer, nil),
  430. }).
  431. WithPullRequest(pr).
  432. Notify(ctx)
  433. }
  434. func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
  435. ctx = withMethod(ctx, "NotifyPullRequestChangeTargetBranch")
  436. if err := pr.LoadIssue(ctx); err != nil {
  437. log.Error("LoadAttributes: %v", err)
  438. return
  439. }
  440. if err := pr.Issue.LoadRepo(db.DefaultContext); err != nil {
  441. log.Error("pr.Issue.LoadRepo: %v", err)
  442. return
  443. }
  444. mode, _ := access_model.AccessLevel(ctx, pr.Issue.Poster, pr.Issue.Repo)
  445. newNotifyInput(pr.Issue.Repo, doer, webhook_module.HookEventPullRequest).
  446. WithPayload(&api.PullRequestPayload{
  447. Action: api.HookIssueEdited,
  448. Index: pr.Issue.Index,
  449. Changes: &api.ChangesPayload{
  450. Ref: &api.ChangesFromPayload{
  451. From: oldBranch,
  452. },
  453. },
  454. PullRequest: convert.ToAPIPullRequest(ctx, pr, nil),
  455. Repository: convert.ToRepo(ctx, pr.Issue.Repo, mode),
  456. Sender: convert.ToUser(doer, nil),
  457. }).
  458. WithPullRequest(pr).
  459. Notify(ctx)
  460. }