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.

webhook.go 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2019 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 webhook
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/log"
  8. "code.gitea.io/gitea/modules/notification/base"
  9. api "code.gitea.io/gitea/modules/structs"
  10. )
  11. type webhookNotifier struct {
  12. base.NullNotifier
  13. }
  14. var (
  15. _ base.Notifier = &webhookNotifier{}
  16. )
  17. // NewNotifier create a new webhookNotifier notifier
  18. func NewNotifier() base.Notifier {
  19. return &webhookNotifier{}
  20. }
  21. func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
  22. if err := issue.LoadPoster(); err != nil {
  23. log.Error("loadPoster: %v", err)
  24. return
  25. }
  26. if err := issue.LoadRepo(); err != nil {
  27. log.Error("LoadRepo: %v", err)
  28. return
  29. }
  30. mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
  31. var err error
  32. if issue.IsPull {
  33. if err = issue.LoadPullRequest(); err != nil {
  34. log.Error("LoadPullRequest: %v", err)
  35. return
  36. }
  37. err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
  38. Action: api.HookIssueLabelCleared,
  39. Index: issue.Index,
  40. PullRequest: issue.PullRequest.APIFormat(),
  41. Repository: issue.Repo.APIFormat(mode),
  42. Sender: doer.APIFormat(),
  43. })
  44. } else {
  45. err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
  46. Action: api.HookIssueLabelCleared,
  47. Index: issue.Index,
  48. Issue: issue.APIFormat(),
  49. Repository: issue.Repo.APIFormat(mode),
  50. Sender: doer.APIFormat(),
  51. })
  52. }
  53. if err != nil {
  54. log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
  55. } else {
  56. go models.HookQueue.Add(issue.RepoID)
  57. }
  58. }