@@ -16,6 +16,7 @@ import (
16
16
"code.gitea.io/gitea/modules/setting"
17
17
"code.gitea.io/gitea/modules/timeutil"
18
18
"code.gitea.io/gitea/modules/util"
19
+ webhook_module "code.gitea.io/gitea/modules/webhook"
19
20
20
21
"xorm.io/builder"
21
22
)
@@ -46,7 +47,7 @@ type ErrHookTaskNotExist struct {
46
47
UUID string
47
48
}
48
49
49
- // IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist .
50
+ // IsErrHookTaskNotExist checks if an error is a ErrHookTaskNotExist .
50
51
func IsErrHookTaskNotExist (err error ) bool {
51
52
_ , ok := err .(ErrHookTaskNotExist )
52
53
return ok
@@ -117,84 +118,22 @@ func IsValidHookContentType(name string) bool {
117
118
return ok
118
119
}
119
120
120
- // HookEvents is a set of web hook events
121
- type HookEvents struct {
122
- Create bool `json:"create"`
123
- Delete bool `json:"delete"`
124
- Fork bool `json:"fork"`
125
- Issues bool `json:"issues"`
126
- IssueAssign bool `json:"issue_assign"`
127
- IssueLabel bool `json:"issue_label"`
128
- IssueMilestone bool `json:"issue_milestone"`
129
- IssueComment bool `json:"issue_comment"`
130
- Push bool `json:"push"`
131
- PullRequest bool `json:"pull_request"`
132
- PullRequestAssign bool `json:"pull_request_assign"`
133
- PullRequestLabel bool `json:"pull_request_label"`
134
- PullRequestMilestone bool `json:"pull_request_milestone"`
135
- PullRequestComment bool `json:"pull_request_comment"`
136
- PullRequestReview bool `json:"pull_request_review"`
137
- PullRequestSync bool `json:"pull_request_sync"`
138
- Wiki bool `json:"wiki"`
139
- Repository bool `json:"repository"`
140
- Release bool `json:"release"`
141
- Package bool `json:"package"`
142
- }
143
-
144
- // HookEvent represents events that will delivery hook.
145
- type HookEvent struct {
146
- PushOnly bool `json:"push_only"`
147
- SendEverything bool `json:"send_everything"`
148
- ChooseEvents bool `json:"choose_events"`
149
- BranchFilter string `json:"branch_filter"`
150
-
151
- HookEvents `json:"events"`
152
- }
153
-
154
- // HookType is the type of a webhook
155
- type HookType = string
156
-
157
- // Types of webhooks
158
- const (
159
- GITEA HookType = "gitea"
160
- GOGS HookType = "gogs"
161
- SLACK HookType = "slack"
162
- DISCORD HookType = "discord"
163
- DINGTALK HookType = "dingtalk"
164
- TELEGRAM HookType = "telegram"
165
- MSTEAMS HookType = "msteams"
166
- FEISHU HookType = "feishu"
167
- MATRIX HookType = "matrix"
168
- WECHATWORK HookType = "wechatwork"
169
- PACKAGIST HookType = "packagist"
170
- )
171
-
172
- // HookStatus is the status of a web hook
173
- type HookStatus int
174
-
175
- // Possible statuses of a web hook
176
- const (
177
- HookStatusNone = iota
178
- HookStatusSucceed
179
- HookStatusFail
180
- )
181
-
182
121
// Webhook represents a web hook object.
183
122
type Webhook struct {
184
- ID int64 `xorm:"pk autoincr"`
185
- RepoID int64 `xorm:"INDEX"` // An ID of 0 indicates either a default or system webhook
186
- OrgID int64 `xorm:"INDEX"`
187
- IsSystemWebhook bool
188
- URL string `xorm:"url TEXT"`
189
- HTTPMethod string `xorm:"http_method"`
190
- ContentType HookContentType
191
- Secret string `xorm:"TEXT"`
192
- Events string `xorm:"TEXT"`
193
- * HookEvent `xorm:"-"`
194
- IsActive bool `xorm:"INDEX"`
195
- Type HookType `xorm:"VARCHAR(16) 'type'"`
196
- Meta string `xorm:"TEXT"` // store hook-specific attributes
197
- LastStatus HookStatus // Last delivery status
123
+ ID int64 `xorm:"pk autoincr"`
124
+ RepoID int64 `xorm:"INDEX"` // An ID of 0 indicates either a default or system webhook
125
+ OrgID int64 `xorm:"INDEX"`
126
+ IsSystemWebhook bool
127
+ URL string `xorm:"url TEXT"`
128
+ HTTPMethod string `xorm:"http_method"`
129
+ ContentType HookContentType
130
+ Secret string `xorm:"TEXT"`
131
+ Events string `xorm:"TEXT"`
132
+ * webhook_module. HookEvent `xorm:"-"`
133
+ IsActive bool `xorm:"INDEX"`
134
+ Type webhook_module. HookType `xorm:"VARCHAR(16) 'type'"`
135
+ Meta string `xorm:"TEXT"` // store hook-specific attributes
136
+ LastStatus webhook_module. HookStatus // Last delivery status
198
137
199
138
// HeaderAuthorizationEncrypted should be accessed using HeaderAuthorization() and SetHeaderAuthorization()
200
139
HeaderAuthorizationEncrypted string `xorm:"TEXT"`
@@ -209,7 +148,7 @@ func init() {
209
148
210
149
// AfterLoad updates the webhook object upon setting a column
211
150
func (w * Webhook ) AfterLoad () {
212
- w .HookEvent = & HookEvent {}
151
+ w .HookEvent = & webhook_module. HookEvent {}
213
152
if err := json .Unmarshal ([]byte (w .Events ), w .HookEvent ); err != nil {
214
153
log .Error ("Unmarshal[%d]: %v" , w .ID , err )
215
154
}
@@ -362,34 +301,34 @@ func (w *Webhook) HasPackageEvent() bool {
362
301
// EventCheckers returns event checkers
363
302
func (w * Webhook ) EventCheckers () []struct {
364
303
Has func () bool
365
- Type HookEventType
304
+ Type webhook_module. HookEventType
366
305
} {
367
306
return []struct {
368
307
Has func () bool
369
- Type HookEventType
308
+ Type webhook_module. HookEventType
370
309
}{
371
- {w .HasCreateEvent , HookEventCreate },
372
- {w .HasDeleteEvent , HookEventDelete },
373
- {w .HasForkEvent , HookEventFork },
374
- {w .HasPushEvent , HookEventPush },
375
- {w .HasIssuesEvent , HookEventIssues },
376
- {w .HasIssuesAssignEvent , HookEventIssueAssign },
377
- {w .HasIssuesLabelEvent , HookEventIssueLabel },
378
- {w .HasIssuesMilestoneEvent , HookEventIssueMilestone },
379
- {w .HasIssueCommentEvent , HookEventIssueComment },
380
- {w .HasPullRequestEvent , HookEventPullRequest },
381
- {w .HasPullRequestAssignEvent , HookEventPullRequestAssign },
382
- {w .HasPullRequestLabelEvent , HookEventPullRequestLabel },
383
- {w .HasPullRequestMilestoneEvent , HookEventPullRequestMilestone },
384
- {w .HasPullRequestCommentEvent , HookEventPullRequestComment },
385
- {w .HasPullRequestApprovedEvent , HookEventPullRequestReviewApproved },
386
- {w .HasPullRequestRejectedEvent , HookEventPullRequestReviewRejected },
387
- {w .HasPullRequestCommentEvent , HookEventPullRequestReviewComment },
388
- {w .HasPullRequestSyncEvent , HookEventPullRequestSync },
389
- {w .HasWikiEvent , HookEventWiki },
390
- {w .HasRepositoryEvent , HookEventRepository },
391
- {w .HasReleaseEvent , HookEventRelease },
392
- {w .HasPackageEvent , HookEventPackage },
310
+ {w .HasCreateEvent , webhook_module . HookEventCreate },
311
+ {w .HasDeleteEvent , webhook_module . HookEventDelete },
312
+ {w .HasForkEvent , webhook_module . HookEventFork },
313
+ {w .HasPushEvent , webhook_module . HookEventPush },
314
+ {w .HasIssuesEvent , webhook_module . HookEventIssues },
315
+ {w .HasIssuesAssignEvent , webhook_module . HookEventIssueAssign },
316
+ {w .HasIssuesLabelEvent , webhook_module . HookEventIssueLabel },
317
+ {w .HasIssuesMilestoneEvent , webhook_module . HookEventIssueMilestone },
318
+ {w .HasIssueCommentEvent , webhook_module . HookEventIssueComment },
319
+ {w .HasPullRequestEvent , webhook_module . HookEventPullRequest },
320
+ {w .HasPullRequestAssignEvent , webhook_module . HookEventPullRequestAssign },
321
+ {w .HasPullRequestLabelEvent , webhook_module . HookEventPullRequestLabel },
322
+ {w .HasPullRequestMilestoneEvent , webhook_module . HookEventPullRequestMilestone },
323
+ {w .HasPullRequestCommentEvent , webhook_module . HookEventPullRequestComment },
324
+ {w .HasPullRequestApprovedEvent , webhook_module . HookEventPullRequestReviewApproved },
325
+ {w .HasPullRequestRejectedEvent , webhook_module . HookEventPullRequestReviewRejected },
326
+ {w .HasPullRequestCommentEvent , webhook_module . HookEventPullRequestReviewComment },
327
+ {w .HasPullRequestSyncEvent , webhook_module . HookEventPullRequestSync },
328
+ {w .HasWikiEvent , webhook_module . HookEventWiki },
329
+ {w .HasRepositoryEvent , webhook_module . HookEventRepository },
330
+ {w .HasReleaseEvent , webhook_module . HookEventRelease },
331
+ {w .HasPackageEvent , webhook_module . HookEventPackage },
393
332
}
394
333
}
395
334
@@ -453,7 +392,7 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
453
392
if err != nil {
454
393
return nil , err
455
394
} else if ! has {
456
- return nil , ErrWebhookNotExist {bean .ID }
395
+ return nil , ErrWebhookNotExist {ID : bean .ID }
457
396
}
458
397
return bean , nil
459
398
}
@@ -541,7 +480,7 @@ func GetSystemOrDefaultWebhook(id int64) (*Webhook, error) {
541
480
if err != nil {
542
481
return nil , err
543
482
} else if ! has {
544
- return nil , ErrWebhookNotExist {id }
483
+ return nil , ErrWebhookNotExist {ID : id }
545
484
}
546
485
return webhook , nil
547
486
}
0 commit comments