@@ -6,6 +6,7 @@ package utils
66import (
77 "fmt"
88 "net/http"
9+ "strconv"
910 "strings"
1011
1112 "code.gitea.io/gitea/models/db"
@@ -157,20 +158,30 @@ func pullHook(events []string, event string) bool {
157158// addHook add the hook specified by `form`, `ownerID` and `repoID`. If there is
158159// an error, write to `ctx` accordingly. Return (webhook, ok)
159160func addHook (ctx * context.APIContext , form * api.CreateHookOption , ownerID , repoID int64 ) (* webhook.Webhook , bool ) {
161+ var isSystemWebhook bool
160162 if ! checkCreateHookOption (ctx , form ) {
161163 return nil , false
162164 }
163165
164166 if len (form .Events ) == 0 {
165167 form .Events = []string {"push" }
166168 }
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+ }
167177 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 ,
174185 HookEvent : & webhook_module.HookEvent {
175186 ChooseEvents : true ,
176187 HookEvents : webhook_module.HookEvents {
0 commit comments