gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package webhook
  4. // HookEventType is the type of a hook event
  5. type HookEventType string
  6. // Types of hook events
  7. const (
  8. HookEventCreate HookEventType = "create"
  9. HookEventDelete HookEventType = "delete"
  10. HookEventFork HookEventType = "fork"
  11. HookEventPush HookEventType = "push"
  12. HookEventIssues HookEventType = "issues"
  13. HookEventIssueAssign HookEventType = "issue_assign"
  14. HookEventIssueLabel HookEventType = "issue_label"
  15. HookEventIssueMilestone HookEventType = "issue_milestone"
  16. HookEventIssueComment HookEventType = "issue_comment"
  17. HookEventPullRequest HookEventType = "pull_request"
  18. HookEventPullRequestAssign HookEventType = "pull_request_assign"
  19. HookEventPullRequestLabel HookEventType = "pull_request_label"
  20. HookEventPullRequestMilestone HookEventType = "pull_request_milestone"
  21. HookEventPullRequestComment HookEventType = "pull_request_comment"
  22. HookEventPullRequestReviewApproved HookEventType = "pull_request_review_approved"
  23. HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected"
  24. HookEventPullRequestReviewComment HookEventType = "pull_request_review_comment"
  25. HookEventPullRequestSync HookEventType = "pull_request_sync"
  26. HookEventPullRequestReviewRequest HookEventType = "pull_request_review_request"
  27. HookEventWiki HookEventType = "wiki"
  28. HookEventRepository HookEventType = "repository"
  29. HookEventRelease HookEventType = "release"
  30. HookEventPackage HookEventType = "package"
  31. HookEventStatus HookEventType = "status"
  32. // once a new event added here, please also added to AllEvents() function
  33. // FIXME: This event should be a group of pull_request_review_xxx events
  34. HookEventPullRequestReview HookEventType = "pull_request_review"
  35. // Actions event only
  36. HookEventSchedule HookEventType = "schedule"
  37. HookEventWorkflowRun HookEventType = "workflow_run"
  38. HookEventWorkflowJob HookEventType = "workflow_job"
  39. )
  40. func AllEvents() []HookEventType {
  41. return []HookEventType{
  42. HookEventCreate,
  43. HookEventDelete,
  44. HookEventFork,
  45. HookEventPush,
  46. HookEventIssues,
  47. HookEventIssueAssign,
  48. HookEventIssueLabel,
  49. HookEventIssueMilestone,
  50. HookEventIssueComment,
  51. HookEventPullRequest,
  52. HookEventPullRequestAssign,
  53. HookEventPullRequestLabel,
  54. HookEventPullRequestMilestone,
  55. HookEventPullRequestComment,
  56. HookEventPullRequestReviewApproved,
  57. HookEventPullRequestReviewRejected,
  58. HookEventPullRequestReviewComment,
  59. HookEventPullRequestSync,
  60. HookEventPullRequestReviewRequest,
  61. HookEventWiki,
  62. HookEventRepository,
  63. HookEventRelease,
  64. HookEventPackage,
  65. HookEventStatus,
  66. HookEventWorkflowRun,
  67. HookEventWorkflowJob,
  68. }
  69. }
  70. // Event returns the HookEventType as an event string
  71. func (h HookEventType) Event() string {
  72. switch h {
  73. case HookEventIssues, HookEventIssueAssign, HookEventIssueLabel, HookEventIssueMilestone:
  74. return "issues"
  75. case HookEventPullRequest, HookEventPullRequestAssign, HookEventPullRequestLabel, HookEventPullRequestMilestone,
  76. HookEventPullRequestSync, HookEventPullRequestReviewRequest:
  77. return "pull_request"
  78. case HookEventIssueComment, HookEventPullRequestComment:
  79. return "issue_comment"
  80. case HookEventPullRequestReviewApproved:
  81. return "pull_request_approved"
  82. case HookEventPullRequestReviewRejected:
  83. return "pull_request_rejected"
  84. case HookEventPullRequestReviewComment:
  85. return "pull_request_comment"
  86. default:
  87. return string(h)
  88. }
  89. }
  90. func (h HookEventType) IsPullRequest() bool {
  91. return h.Event() == "pull_request"
  92. }
  93. // HookType is the type of a webhook
  94. type HookType = string
  95. // Types of webhooks
  96. const (
  97. GITEA HookType = "gitea"
  98. GOGS HookType = "gogs"
  99. SLACK HookType = "slack"
  100. DISCORD HookType = "discord"
  101. DINGTALK HookType = "dingtalk"
  102. TELEGRAM HookType = "telegram"
  103. MSTEAMS HookType = "msteams"
  104. FEISHU HookType = "feishu"
  105. MATRIX HookType = "matrix"
  106. WECHATWORK HookType = "wechatwork"
  107. PACKAGIST HookType = "packagist"
  108. )
  109. // HookStatus is the status of a web hook
  110. type HookStatus int
  111. // Possible statuses of a web hook
  112. const (
  113. HookStatusNone HookStatus = iota
  114. HookStatusSucceed
  115. HookStatusFail
  116. )