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