Skip to content

Commit f8a1bad

Browse files
Fix: system webhooks API bug (#28531)
- Fix the bug about admin/hooks API that `GET /admin/hooks` can only fetch system_hooks, `POST /admin/hooks` can only create default_hooks.
1 parent b6e0957 commit f8a1bad

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

routers/api/v1/utils/hook.go

Lines changed: 17 additions & 6 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"
@@ -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)
159160
func 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

Comments
 (0)