Skip to content

Commit 3dbd2d9

Browse files
authored
Remove old HookEventType (#22358)
Supplement to #22256.
1 parent f74293f commit 3dbd2d9

File tree

2 files changed

+35
-98
lines changed

2 files changed

+35
-98
lines changed

models/webhook/hooktask.go

-63
Original file line numberDiff line numberDiff line change
@@ -24,69 +24,6 @@ import (
2424
// \___|_ / \____/ \____/|__|_ \ |____| (____ /____ >__|_ \
2525
// \/ \/ \/ \/ \/
2626

27-
// HookEventType is the type of an hook event
28-
type HookEventType string
29-
30-
// Types of hook events
31-
const (
32-
HookEventCreate HookEventType = "create"
33-
HookEventDelete HookEventType = "delete"
34-
HookEventFork HookEventType = "fork"
35-
HookEventPush HookEventType = "push"
36-
HookEventIssues HookEventType = "issues"
37-
HookEventIssueAssign HookEventType = "issue_assign"
38-
HookEventIssueLabel HookEventType = "issue_label"
39-
HookEventIssueMilestone HookEventType = "issue_milestone"
40-
HookEventIssueComment HookEventType = "issue_comment"
41-
HookEventPullRequest HookEventType = "pull_request"
42-
HookEventPullRequestAssign HookEventType = "pull_request_assign"
43-
HookEventPullRequestLabel HookEventType = "pull_request_label"
44-
HookEventPullRequestMilestone HookEventType = "pull_request_milestone"
45-
HookEventPullRequestComment HookEventType = "pull_request_comment"
46-
HookEventPullRequestReviewApproved HookEventType = "pull_request_review_approved"
47-
HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected"
48-
HookEventPullRequestReviewComment HookEventType = "pull_request_review_comment"
49-
HookEventPullRequestSync HookEventType = "pull_request_sync"
50-
HookEventWiki HookEventType = "wiki"
51-
HookEventRepository HookEventType = "repository"
52-
HookEventRelease HookEventType = "release"
53-
HookEventPackage HookEventType = "package"
54-
)
55-
56-
// Event returns the HookEventType as an event string
57-
func (h HookEventType) Event() string {
58-
switch h {
59-
case HookEventCreate:
60-
return "create"
61-
case HookEventDelete:
62-
return "delete"
63-
case HookEventFork:
64-
return "fork"
65-
case HookEventPush:
66-
return "push"
67-
case HookEventIssues, HookEventIssueAssign, HookEventIssueLabel, HookEventIssueMilestone:
68-
return "issues"
69-
case HookEventPullRequest, HookEventPullRequestAssign, HookEventPullRequestLabel, HookEventPullRequestMilestone,
70-
HookEventPullRequestSync:
71-
return "pull_request"
72-
case HookEventIssueComment, HookEventPullRequestComment:
73-
return "issue_comment"
74-
case HookEventPullRequestReviewApproved:
75-
return "pull_request_approved"
76-
case HookEventPullRequestReviewRejected:
77-
return "pull_request_rejected"
78-
case HookEventPullRequestReviewComment:
79-
return "pull_request_comment"
80-
case HookEventWiki:
81-
return "wiki"
82-
case HookEventRepository:
83-
return "repository"
84-
case HookEventRelease:
85-
return "release"
86-
}
87-
return ""
88-
}
89-
9027
// HookRequest represents hook task request information.
9128
type HookRequest struct {
9229
URL string `json:"url"`

routers/api/v1/utils/hook.go

+35-35
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ func toAPIHook(ctx *context.APIContext, repoLink string, hook *webhook.Webhook)
107107
}
108108

109109
func issuesHook(events []string, event string) bool {
110-
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook.HookEventIssues), events, true)
110+
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook_module.HookEventIssues), events, true)
111111
}
112112

113113
func pullHook(events []string, event string) bool {
114-
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook.HookEventPullRequest), events, true)
114+
return util.IsStringInSlice(event, events, true) || util.IsStringInSlice(string(webhook_module.HookEventPullRequest), events, true)
115115
}
116116

117117
// addHook add the hook specified by `form`, `orgID` and `repoID`. If there is
@@ -130,25 +130,25 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
130130
HookEvent: &webhook_module.HookEvent{
131131
ChooseEvents: true,
132132
HookEvents: webhook_module.HookEvents{
133-
Create: util.IsStringInSlice(string(webhook.HookEventCreate), form.Events, true),
134-
Delete: util.IsStringInSlice(string(webhook.HookEventDelete), form.Events, true),
135-
Fork: util.IsStringInSlice(string(webhook.HookEventFork), form.Events, true),
133+
Create: util.IsStringInSlice(string(webhook_module.HookEventCreate), form.Events, true),
134+
Delete: util.IsStringInSlice(string(webhook_module.HookEventDelete), form.Events, true),
135+
Fork: util.IsStringInSlice(string(webhook_module.HookEventFork), form.Events, true),
136136
Issues: issuesHook(form.Events, "issues_only"),
137-
IssueAssign: issuesHook(form.Events, string(webhook.HookEventIssueAssign)),
138-
IssueLabel: issuesHook(form.Events, string(webhook.HookEventIssueLabel)),
139-
IssueMilestone: issuesHook(form.Events, string(webhook.HookEventIssueMilestone)),
140-
IssueComment: issuesHook(form.Events, string(webhook.HookEventIssueComment)),
141-
Push: util.IsStringInSlice(string(webhook.HookEventPush), form.Events, true),
137+
IssueAssign: issuesHook(form.Events, string(webhook_module.HookEventIssueAssign)),
138+
IssueLabel: issuesHook(form.Events, string(webhook_module.HookEventIssueLabel)),
139+
IssueMilestone: issuesHook(form.Events, string(webhook_module.HookEventIssueMilestone)),
140+
IssueComment: issuesHook(form.Events, string(webhook_module.HookEventIssueComment)),
141+
Push: util.IsStringInSlice(string(webhook_module.HookEventPush), form.Events, true),
142142
PullRequest: pullHook(form.Events, "pull_request_only"),
143-
PullRequestAssign: pullHook(form.Events, string(webhook.HookEventPullRequestAssign)),
144-
PullRequestLabel: pullHook(form.Events, string(webhook.HookEventPullRequestLabel)),
145-
PullRequestMilestone: pullHook(form.Events, string(webhook.HookEventPullRequestMilestone)),
146-
PullRequestComment: pullHook(form.Events, string(webhook.HookEventPullRequestComment)),
143+
PullRequestAssign: pullHook(form.Events, string(webhook_module.HookEventPullRequestAssign)),
144+
PullRequestLabel: pullHook(form.Events, string(webhook_module.HookEventPullRequestLabel)),
145+
PullRequestMilestone: pullHook(form.Events, string(webhook_module.HookEventPullRequestMilestone)),
146+
PullRequestComment: pullHook(form.Events, string(webhook_module.HookEventPullRequestComment)),
147147
PullRequestReview: pullHook(form.Events, "pull_request_review"),
148-
PullRequestSync: pullHook(form.Events, string(webhook.HookEventPullRequestSync)),
149-
Wiki: util.IsStringInSlice(string(webhook.HookEventWiki), form.Events, true),
150-
Repository: util.IsStringInSlice(string(webhook.HookEventRepository), form.Events, true),
151-
Release: util.IsStringInSlice(string(webhook.HookEventRelease), form.Events, true),
148+
PullRequestSync: pullHook(form.Events, string(webhook_module.HookEventPullRequestSync)),
149+
Wiki: util.IsStringInSlice(string(webhook_module.HookEventWiki), form.Events, true),
150+
Repository: util.IsStringInSlice(string(webhook_module.HookEventRepository), form.Events, true),
151+
Release: util.IsStringInSlice(string(webhook_module.HookEventRelease), form.Events, true),
152152
},
153153
BranchFilter: form.BranchFilter,
154154
},
@@ -277,14 +277,14 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
277277
w.PushOnly = false
278278
w.SendEverything = false
279279
w.ChooseEvents = true
280-
w.Create = util.IsStringInSlice(string(webhook.HookEventCreate), form.Events, true)
281-
w.Push = util.IsStringInSlice(string(webhook.HookEventPush), form.Events, true)
282-
w.Create = util.IsStringInSlice(string(webhook.HookEventCreate), form.Events, true)
283-
w.Delete = util.IsStringInSlice(string(webhook.HookEventDelete), form.Events, true)
284-
w.Fork = util.IsStringInSlice(string(webhook.HookEventFork), form.Events, true)
285-
w.Repository = util.IsStringInSlice(string(webhook.HookEventRepository), form.Events, true)
286-
w.Wiki = util.IsStringInSlice(string(webhook.HookEventWiki), form.Events, true)
287-
w.Release = util.IsStringInSlice(string(webhook.HookEventRelease), form.Events, true)
280+
w.Create = util.IsStringInSlice(string(webhook_module.HookEventCreate), form.Events, true)
281+
w.Push = util.IsStringInSlice(string(webhook_module.HookEventPush), form.Events, true)
282+
w.Create = util.IsStringInSlice(string(webhook_module.HookEventCreate), form.Events, true)
283+
w.Delete = util.IsStringInSlice(string(webhook_module.HookEventDelete), form.Events, true)
284+
w.Fork = util.IsStringInSlice(string(webhook_module.HookEventFork), form.Events, true)
285+
w.Repository = util.IsStringInSlice(string(webhook_module.HookEventRepository), form.Events, true)
286+
w.Wiki = util.IsStringInSlice(string(webhook_module.HookEventWiki), form.Events, true)
287+
w.Release = util.IsStringInSlice(string(webhook_module.HookEventRelease), form.Events, true)
288288
w.BranchFilter = form.BranchFilter
289289

290290
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
@@ -295,19 +295,19 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *webhook.Webh
295295

296296
// Issues
297297
w.Issues = issuesHook(form.Events, "issues_only")
298-
w.IssueAssign = issuesHook(form.Events, string(webhook.HookEventIssueAssign))
299-
w.IssueLabel = issuesHook(form.Events, string(webhook.HookEventIssueLabel))
300-
w.IssueMilestone = issuesHook(form.Events, string(webhook.HookEventIssueMilestone))
301-
w.IssueComment = issuesHook(form.Events, string(webhook.HookEventIssueComment))
298+
w.IssueAssign = issuesHook(form.Events, string(webhook_module.HookEventIssueAssign))
299+
w.IssueLabel = issuesHook(form.Events, string(webhook_module.HookEventIssueLabel))
300+
w.IssueMilestone = issuesHook(form.Events, string(webhook_module.HookEventIssueMilestone))
301+
w.IssueComment = issuesHook(form.Events, string(webhook_module.HookEventIssueComment))
302302

303303
// Pull requests
304304
w.PullRequest = pullHook(form.Events, "pull_request_only")
305-
w.PullRequestAssign = pullHook(form.Events, string(webhook.HookEventPullRequestAssign))
306-
w.PullRequestLabel = pullHook(form.Events, string(webhook.HookEventPullRequestLabel))
307-
w.PullRequestMilestone = pullHook(form.Events, string(webhook.HookEventPullRequestMilestone))
308-
w.PullRequestComment = pullHook(form.Events, string(webhook.HookEventPullRequestComment))
305+
w.PullRequestAssign = pullHook(form.Events, string(webhook_module.HookEventPullRequestAssign))
306+
w.PullRequestLabel = pullHook(form.Events, string(webhook_module.HookEventPullRequestLabel))
307+
w.PullRequestMilestone = pullHook(form.Events, string(webhook_module.HookEventPullRequestMilestone))
308+
w.PullRequestComment = pullHook(form.Events, string(webhook_module.HookEventPullRequestComment))
309309
w.PullRequestReview = pullHook(form.Events, "pull_request_review")
310-
w.PullRequestSync = pullHook(form.Events, string(webhook.HookEventPullRequestSync))
310+
w.PullRequestSync = pullHook(form.Events, string(webhook_module.HookEventPullRequestSync))
311311

312312
if err := w.UpdateEvent(); err != nil {
313313
ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)

0 commit comments

Comments
 (0)