aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvincent <38434877+pulltheflower@users.noreply.github.com>2023-12-31 12:31:50 +0800
committerGitHub <noreply@github.com>2023-12-31 04:31:50 +0000
commitf8a1bad883aa4697b4001f74e2074898d7162aef (patch)
tree661c77a32a24139f2a9455e739572205ff1a42e3
parentb6e0957b9c84d1da0c7805f8e45ce7988badc7c2 (diff)
downloadgitea-f8a1bad883aa4697b4001f74e2074898d7162aef.tar.gz
gitea-f8a1bad883aa4697b4001f74e2074898d7162aef.zip
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.
-rw-r--r--routers/api/v1/utils/hook.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go
index 1207be25ac..28b21ab8db 100644
--- a/routers/api/v1/utils/hook.go
+++ b/routers/api/v1/utils/hook.go
@@ -6,6 +6,7 @@ package utils
import (
"fmt"
"net/http"
+ "strconv"
"strings"
"code.gitea.io/gitea/models/db"
@@ -157,6 +158,7 @@ func pullHook(events []string, event string) bool {
// addHook add the hook specified by `form`, `ownerID` and `repoID`. If there is
// an error, write to `ctx` accordingly. Return (webhook, ok)
func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoID int64) (*webhook.Webhook, bool) {
+ var isSystemWebhook bool
if !checkCreateHookOption(ctx, form) {
return nil, false
}
@@ -164,13 +166,22 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
if len(form.Events) == 0 {
form.Events = []string{"push"}
}
+ if form.Config["is_system_webhook"] != "" {
+ sw, err := strconv.ParseBool(form.Config["is_system_webhook"])
+ if err != nil {
+ ctx.Error(http.StatusUnprocessableEntity, "", "Invalid is_system_webhook value")
+ return nil, false
+ }
+ isSystemWebhook = sw
+ }
w := &webhook.Webhook{
- OwnerID: ownerID,
- RepoID: repoID,
- URL: form.Config["url"],
- ContentType: webhook.ToHookContentType(form.Config["content_type"]),
- Secret: form.Config["secret"],
- HTTPMethod: "POST",
+ OwnerID: ownerID,
+ RepoID: repoID,
+ URL: form.Config["url"],
+ ContentType: webhook.ToHookContentType(form.Config["content_type"]),
+ Secret: form.Config["secret"],
+ HTTPMethod: "POST",
+ IsSystemWebhook: isSystemWebhook,
HookEvent: &webhook_module.HookEvent{
ChooseEvents: true,
HookEvents: webhook_module.HookEvents{