@@ -14,10 +14,9 @@ import (
14
14
"code.gitea.io/gitea/modules/context"
15
15
"code.gitea.io/gitea/modules/convert"
16
16
api "code.gitea.io/gitea/modules/structs"
17
+ "code.gitea.io/gitea/modules/util"
17
18
"code.gitea.io/gitea/routers/utils"
18
19
"code.gitea.io/gitea/services/webhook"
19
-
20
- "github.com/unknwon/com"
21
20
)
22
21
23
22
// GetOrgHook get an organization's webhook. If there is an error, write to
@@ -89,11 +88,11 @@ func AddRepoHook(ctx *context.APIContext, form *api.CreateHookOption) {
89
88
}
90
89
91
90
func issuesHook (events []string , event string ) bool {
92
- return com . IsSliceContainsStr ( events , event ) || com . IsSliceContainsStr ( events , string (models .HookEventIssues ))
91
+ return util . IsStringInSlice ( event , events , true ) || util . IsStringInSlice ( string (models .HookEventIssues ), events , true )
93
92
}
94
93
95
94
func pullHook (events []string , event string ) bool {
96
- return com . IsSliceContainsStr ( events , event ) || com . IsSliceContainsStr ( events , string (models .HookEventPullRequest ))
95
+ return util . IsStringInSlice ( event , events , true ) || util . IsStringInSlice ( string (models .HookEventPullRequest ), events , true )
97
96
}
98
97
99
98
// addHook add the hook specified by `form`, `orgID` and `repoID`. If there is
@@ -112,24 +111,24 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
112
111
HookEvent : & models.HookEvent {
113
112
ChooseEvents : true ,
114
113
HookEvents : models.HookEvents {
115
- Create : com . IsSliceContainsStr ( form . Events , string (models .HookEventCreate )),
116
- Delete : com . IsSliceContainsStr ( form . Events , string (models .HookEventDelete )),
117
- Fork : com . IsSliceContainsStr ( form . Events , string (models .HookEventFork )),
114
+ Create : util . IsStringInSlice ( string (models .HookEventCreate ), form . Events , true ),
115
+ Delete : util . IsStringInSlice ( string (models .HookEventDelete ), form . Events , true ),
116
+ Fork : util . IsStringInSlice ( string (models .HookEventFork ), form . Events , true ),
118
117
Issues : issuesHook (form .Events , "issues_only" ),
119
118
IssueAssign : issuesHook (form .Events , string (models .HookEventIssueAssign )),
120
119
IssueLabel : issuesHook (form .Events , string (models .HookEventIssueLabel )),
121
120
IssueMilestone : issuesHook (form .Events , string (models .HookEventIssueMilestone )),
122
121
IssueComment : issuesHook (form .Events , string (models .HookEventIssueComment )),
123
- Push : com . IsSliceContainsStr ( form . Events , string (models .HookEventPush )),
122
+ Push : util . IsStringInSlice ( string (models .HookEventPush ), form . Events , true ),
124
123
PullRequest : pullHook (form .Events , "pull_request_only" ),
125
124
PullRequestAssign : pullHook (form .Events , string (models .HookEventPullRequestAssign )),
126
125
PullRequestLabel : pullHook (form .Events , string (models .HookEventPullRequestLabel )),
127
126
PullRequestMilestone : pullHook (form .Events , string (models .HookEventPullRequestMilestone )),
128
127
PullRequestComment : pullHook (form .Events , string (models .HookEventPullRequestComment )),
129
128
PullRequestReview : pullHook (form .Events , "pull_request_review" ),
130
129
PullRequestSync : pullHook (form .Events , string (models .HookEventPullRequestSync )),
131
- Repository : com . IsSliceContainsStr ( form . Events , string (models .HookEventRepository )),
132
- Release : com . IsSliceContainsStr ( form . Events , string (models .HookEventRelease )),
130
+ Repository : util . IsStringInSlice ( string (models .HookEventRepository ), form . Events , true ),
131
+ Release : util . IsStringInSlice ( string (models .HookEventRelease ), form . Events , true ),
133
132
},
134
133
BranchFilter : form .BranchFilter ,
135
134
},
@@ -244,18 +243,18 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho
244
243
w .PushOnly = false
245
244
w .SendEverything = false
246
245
w .ChooseEvents = true
247
- w .Create = com . IsSliceContainsStr ( form . Events , string (models .HookEventCreate ))
248
- w .Push = com . IsSliceContainsStr ( form . Events , string (models .HookEventPush ))
249
- w .PullRequest = com . IsSliceContainsStr ( form . Events , string (models .HookEventPullRequest ))
250
- w .Create = com . IsSliceContainsStr ( form . Events , string (models .HookEventCreate ))
251
- w .Delete = com . IsSliceContainsStr ( form . Events , string (models .HookEventDelete ))
252
- w .Fork = com . IsSliceContainsStr ( form . Events , string (models .HookEventFork ))
253
- w .Issues = com . IsSliceContainsStr ( form . Events , string (models .HookEventIssues ))
254
- w .IssueComment = com . IsSliceContainsStr ( form . Events , string (models .HookEventIssueComment ))
255
- w .Push = com . IsSliceContainsStr ( form . Events , string (models .HookEventPush ))
256
- w .PullRequest = com . IsSliceContainsStr ( form . Events , string (models .HookEventPullRequest ))
257
- w .Repository = com . IsSliceContainsStr ( form . Events , string (models .HookEventRepository ))
258
- w .Release = com . IsSliceContainsStr ( form . Events , string (models .HookEventRelease ))
246
+ w .Create = util . IsStringInSlice ( string (models .HookEventCreate ), form . Events , true )
247
+ w .Push = util . IsStringInSlice ( string (models .HookEventPush ), form . Events , true )
248
+ w .PullRequest = util . IsStringInSlice ( string (models .HookEventPullRequest ), form . Events , true )
249
+ w .Create = util . IsStringInSlice ( string (models .HookEventCreate ), form . Events , true )
250
+ w .Delete = util . IsStringInSlice ( string (models .HookEventDelete ), form . Events , true )
251
+ w .Fork = util . IsStringInSlice ( string (models .HookEventFork ), form . Events , true )
252
+ w .Issues = util . IsStringInSlice ( string (models .HookEventIssues ), form . Events , true )
253
+ w .IssueComment = util . IsStringInSlice ( string (models .HookEventIssueComment ), form . Events , true )
254
+ w .Push = util . IsStringInSlice ( string (models .HookEventPush ), form . Events , true )
255
+ w .PullRequest = util . IsStringInSlice ( string (models .HookEventPullRequest ), form . Events , true )
256
+ w .Repository = util . IsStringInSlice ( string (models .HookEventRepository ), form . Events , true )
257
+ w .Release = util . IsStringInSlice ( string (models .HookEventRelease ), form . Events , true )
259
258
w .BranchFilter = form .BranchFilter
260
259
261
260
if err := w .UpdateEvent (); err != nil {
0 commit comments