@@ -6,6 +6,7 @@ package utils
6
6
import (
7
7
"fmt"
8
8
"net/http"
9
+ "strconv"
9
10
"strings"
10
11
11
12
user_model "code.gitea.io/gitea/models/user"
@@ -162,20 +163,30 @@ func pullHook(events []string, event string) bool {
162
163
// addHook add the hook specified by `form`, `ownerID` and `repoID`. If there is
163
164
// an error, write to `ctx` accordingly. Return (webhook, ok)
164
165
func addHook (ctx * context.APIContext , form * api.CreateHookOption , ownerID , repoID int64 ) (* webhook.Webhook , bool ) {
166
+ var isSystemWebhook bool
165
167
if ! checkCreateHookOption (ctx , form ) {
166
168
return nil , false
167
169
}
168
170
169
171
if len (form .Events ) == 0 {
170
172
form .Events = []string {"push" }
171
173
}
174
+ if form .Config ["is_system_webhook" ] != "" {
175
+ sw , err := strconv .ParseBool (form .Config ["is_system_webhook" ])
176
+ if err != nil {
177
+ ctx .Error (http .StatusUnprocessableEntity , "" , "Invalid is_system_webhook value" )
178
+ return nil , false
179
+ }
180
+ isSystemWebhook = sw
181
+ }
172
182
w := & webhook.Webhook {
173
- OwnerID : ownerID ,
174
- RepoID : repoID ,
175
- URL : form .Config ["url" ],
176
- ContentType : webhook .ToHookContentType (form .Config ["content_type" ]),
177
- Secret : form .Config ["secret" ],
178
- HTTPMethod : "POST" ,
183
+ OwnerID : ownerID ,
184
+ RepoID : repoID ,
185
+ URL : form .Config ["url" ],
186
+ ContentType : webhook .ToHookContentType (form .Config ["content_type" ]),
187
+ Secret : form .Config ["secret" ],
188
+ HTTPMethod : "POST" ,
189
+ IsSystemWebhook : isSystemWebhook ,
179
190
HookEvent : & webhook_module.HookEvent {
180
191
ChooseEvents : true ,
181
192
HookEvents : webhook_module.HookEvents {
0 commit comments