2023-01-01 16:23:15 +01:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package webhook
|
|
|
|
|
|
|
|
// HookEventType is the type of a hook event
|
|
|
|
type HookEventType string
|
|
|
|
|
|
|
|
// Types of hook events
|
|
|
|
const (
|
|
|
|
HookEventCreate HookEventType = "create"
|
|
|
|
HookEventDelete HookEventType = "delete"
|
|
|
|
HookEventFork HookEventType = "fork"
|
|
|
|
HookEventPush HookEventType = "push"
|
|
|
|
HookEventIssues HookEventType = "issues"
|
|
|
|
HookEventIssueAssign HookEventType = "issue_assign"
|
|
|
|
HookEventIssueLabel HookEventType = "issue_label"
|
|
|
|
HookEventIssueMilestone HookEventType = "issue_milestone"
|
|
|
|
HookEventIssueComment HookEventType = "issue_comment"
|
|
|
|
HookEventPullRequest HookEventType = "pull_request"
|
|
|
|
HookEventPullRequestAssign HookEventType = "pull_request_assign"
|
|
|
|
HookEventPullRequestLabel HookEventType = "pull_request_label"
|
|
|
|
HookEventPullRequestMilestone HookEventType = "pull_request_milestone"
|
|
|
|
HookEventPullRequestComment HookEventType = "pull_request_comment"
|
|
|
|
HookEventPullRequestReviewApproved HookEventType = "pull_request_review_approved"
|
|
|
|
HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected"
|
|
|
|
HookEventPullRequestReviewComment HookEventType = "pull_request_review_comment"
|
|
|
|
HookEventPullRequestSync HookEventType = "pull_request_sync"
|
2023-05-25 10:06:27 +08:00
|
|
|
HookEventPullRequestReviewRequest HookEventType = "pull_request_review_request"
|
2023-01-01 16:23:15 +01:00
|
|
|
HookEventWiki HookEventType = "wiki"
|
|
|
|
HookEventRepository HookEventType = "repository"
|
|
|
|
HookEventRelease HookEventType = "release"
|
|
|
|
HookEventPackage HookEventType = "package"
|
2024-01-13 05:50:38 +08:00
|
|
|
HookEventSchedule HookEventType = "schedule"
|
2024-11-06 22:41:49 -08:00
|
|
|
HookEventStatus HookEventType = "status"
|
2023-01-01 16:23:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Event returns the HookEventType as an event string
|
|
|
|
func (h HookEventType) Event() string {
|
|
|
|
switch h {
|
|
|
|
case HookEventCreate:
|
|
|
|
return "create"
|
|
|
|
case HookEventDelete:
|
|
|
|
return "delete"
|
|
|
|
case HookEventFork:
|
|
|
|
return "fork"
|
|
|
|
case HookEventPush:
|
|
|
|
return "push"
|
|
|
|
case HookEventIssues, HookEventIssueAssign, HookEventIssueLabel, HookEventIssueMilestone:
|
|
|
|
return "issues"
|
|
|
|
case HookEventPullRequest, HookEventPullRequestAssign, HookEventPullRequestLabel, HookEventPullRequestMilestone,
|
2023-05-25 10:06:27 +08:00
|
|
|
HookEventPullRequestSync, HookEventPullRequestReviewRequest:
|
2023-01-01 16:23:15 +01:00
|
|
|
return "pull_request"
|
|
|
|
case HookEventIssueComment, HookEventPullRequestComment:
|
|
|
|
return "issue_comment"
|
|
|
|
case HookEventPullRequestReviewApproved:
|
|
|
|
return "pull_request_approved"
|
|
|
|
case HookEventPullRequestReviewRejected:
|
|
|
|
return "pull_request_rejected"
|
|
|
|
case HookEventPullRequestReviewComment:
|
|
|
|
return "pull_request_comment"
|
|
|
|
case HookEventWiki:
|
|
|
|
return "wiki"
|
|
|
|
case HookEventRepository:
|
|
|
|
return "repository"
|
|
|
|
case HookEventRelease:
|
|
|
|
return "release"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
Update status check for all supported on.pull_request.types in Gitea (#33117)
Thanks @Zettat123
Follow #33116
Fix #33051
on.pull_request.types doc:
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
on.pull_request.types added in this PR:
```
assigned, unassigned, review_requested, review_request_removed, milestoned, demilestoned, labeled, unlabeled
```
unsupported types in Gitea:
```
// Unsupported activity types:
// converted_to_draft, ready_for_review, locked, unlocked, auto_merge_enabled, auto_merge_disabled, enqueued, dequeued
```
TODO:
- [x] add test
2025-01-08 02:58:47 +09:00
|
|
|
func (h HookEventType) IsPullRequest() bool {
|
|
|
|
return h.Event() == "pull_request"
|
|
|
|
}
|
|
|
|
|
2023-01-01 16:23:15 +01:00
|
|
|
// HookType is the type of a webhook
|
|
|
|
type HookType = string
|
|
|
|
|
|
|
|
// Types of webhooks
|
|
|
|
const (
|
|
|
|
GITEA HookType = "gitea"
|
|
|
|
GOGS HookType = "gogs"
|
|
|
|
SLACK HookType = "slack"
|
|
|
|
DISCORD HookType = "discord"
|
|
|
|
DINGTALK HookType = "dingtalk"
|
|
|
|
TELEGRAM HookType = "telegram"
|
|
|
|
MSTEAMS HookType = "msteams"
|
|
|
|
FEISHU HookType = "feishu"
|
|
|
|
MATRIX HookType = "matrix"
|
|
|
|
WECHATWORK HookType = "wechatwork"
|
|
|
|
PACKAGIST HookType = "packagist"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HookStatus is the status of a web hook
|
|
|
|
type HookStatus int
|
|
|
|
|
|
|
|
// Possible statuses of a web hook
|
|
|
|
const (
|
|
|
|
HookStatusNone HookStatus = iota
|
|
|
|
HookStatusSucceed
|
|
|
|
HookStatusFail
|
|
|
|
)
|