Skip to content

Commit 4f808c5

Browse files
committed
Fix webhook API to get a webhook
1 parent ac3c6f3 commit 4f808c5

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

models/webhook/webhook.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,21 @@ func (w *Webhook) HasEvent(evt webhook_module.HookEventType) bool {
177177
return w.HookEvents[evt]
178178
}
179179

180-
// EventsArray returns an array of hook events
180+
// EventsArray returns an array of hook events,
181181
func (w *Webhook) EventsArray() []string {
182-
events := make([]string, 0, 7)
182+
if w.SendEverything {
183+
events := make([]string, 0, len(webhook_module.AllEvents()))
184+
for _, evt := range webhook_module.AllEvents() {
185+
events = append(events, string(evt))
186+
}
187+
return events
188+
}
189+
190+
if w.PushOnly {
191+
return []string{string(webhook_module.HookEventPush)}
192+
}
183193

194+
events := make([]string, 0, len(w.HookEvents))
184195
for event, enabled := range w.HookEvents {
185196
if enabled {
186197
events = append(events, string(event))

modules/webhook/type.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,40 @@ const (
3434
HookEventPackage HookEventType = "package"
3535
HookEventSchedule HookEventType = "schedule"
3636
HookEventStatus HookEventType = "status"
37+
// once a new event added here, please also added to AllEvents() function
3738
)
3839

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+
HookEventPullRequestReview,
57+
HookEventPullRequestReviewApproved,
58+
HookEventPullRequestReviewRejected,
59+
HookEventPullRequestReviewComment,
60+
HookEventPullRequestSync,
61+
HookEventPullRequestReviewRequest,
62+
HookEventWiki,
63+
HookEventRepository,
64+
HookEventRelease,
65+
HookEventPackage,
66+
HookEventSchedule,
67+
HookEventStatus,
68+
}
69+
}
70+
3971
// Event returns the HookEventType as an event string
4072
func (h HookEventType) Event() string {
4173
switch h {

0 commit comments

Comments
 (0)