Refactor webhook events (#33337)

Extract from #33320

This PR uses a map instead of a struct to store webhook event
information. It removes many duplicated functions and makes the logic
clearer.
This commit is contained in:
Lunny Xiao 2025-01-23 10:53:06 -08:00 committed by GitHub
parent 594b8350b1
commit e94f37f95e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 176 additions and 335 deletions

View file

@ -54,9 +54,9 @@ func TestWebhook_UpdateEvent(t *testing.T) {
SendEverything: false,
ChooseEvents: false,
HookEvents: webhook_module.HookEvents{
Create: false,
Push: true,
PullRequest: false,
webhook_module.HookEventCreate: false,
webhook_module.HookEventPush: true,
webhook_module.HookEventPullRequest: false,
},
}
webhook.HookEvent = hookEvent
@ -68,13 +68,13 @@ func TestWebhook_UpdateEvent(t *testing.T) {
}
func TestWebhook_EventsArray(t *testing.T) {
assert.Equal(t, []string{
assert.EqualValues(t, []string{
"create", "delete", "fork", "push",
"issues", "issue_assign", "issue_label", "issue_milestone", "issue_comment",
"pull_request", "pull_request_assign", "pull_request_label", "pull_request_milestone",
"pull_request_comment", "pull_request_review_approved", "pull_request_review_rejected",
"pull_request_review_comment", "pull_request_sync", "wiki", "repository", "release",
"package", "pull_request_review_request",
"pull_request_review_comment", "pull_request_sync", "pull_request_review_request", "wiki", "repository", "release",
"package", "status",
},
(&Webhook{
HookEvent: &webhook_module.HookEvent{SendEverything: true},