Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit 72875fd

Browse files
committed
Fix: system webhooks API bug
1 parent 4eb2a29 commit 72875fd

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

routers/api/v1/utils/hook.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package utils
66
import (
77
"fmt"
88
"net/http"
9+
"strconv"
910
"strings"
1011

1112
"code.gitea.io/gitea/models/db"
@@ -164,13 +165,20 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
164165
if len(form.Events) == 0 {
165166
form.Events = []string{"push"}
166167
}
168+
169+
isSystemWebhook, err := strconv.ParseBool(form.Config["is_system_webhook"])
170+
if err != nil {
171+
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid is_system_webhook value")
172+
return nil, false
173+
}
167174
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",
175+
OwnerID: ownerID,
176+
RepoID: repoID,
177+
URL: form.Config["url"],
178+
ContentType: webhook.ToHookContentType(form.Config["content_type"]),
179+
Secret: form.Config["secret"],
180+
HTTPMethod: "POST",
181+
IsSystemWebhook: isSystemWebhook,
174182
HookEvent: &webhook_module.HookEvent{
175183
ChooseEvents: true,
176184
HookEvents: webhook_module.HookEvents{
@@ -200,7 +208,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
200208
IsActive: form.Active,
201209
Type: form.Type,
202210
}
203-
err := w.SetHeaderAuthorization(form.AuthorizationHeader)
211+
err = w.SetHeaderAuthorization(form.AuthorizationHeader)
204212
if err != nil {
205213
ctx.Error(http.StatusInternalServerError, "SetHeaderAuthorization", err)
206214
return nil, false

0 commit comments

Comments
 (0)