mirror of
https://github.com/go-gitea/gitea
synced 2024-12-25 01:54:26 +00:00
Backport #28531 by @pulltheflower - Fix the bug about admin/hooks API that `GET /admin/hooks` can only fetch system_hooks, `POST /admin/hooks` can only create default_hooks. Co-authored-by: vincent <38434877+pulltheflower@users.noreply.github.com>
This commit is contained in:
parent
3e1bd61000
commit
3c79315cf2
@ -6,6 +6,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -162,6 +163,7 @@ func pullHook(events []string, event string) bool {
|
|||||||
// addHook add the hook specified by `form`, `ownerID` and `repoID`. If there is
|
// addHook add the hook specified by `form`, `ownerID` and `repoID`. If there is
|
||||||
// an error, write to `ctx` accordingly. Return (webhook, ok)
|
// an error, write to `ctx` accordingly. Return (webhook, ok)
|
||||||
func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoID int64) (*webhook.Webhook, bool) {
|
func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoID int64) (*webhook.Webhook, bool) {
|
||||||
|
var isSystemWebhook bool
|
||||||
if !checkCreateHookOption(ctx, form) {
|
if !checkCreateHookOption(ctx, form) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -169,6 +171,14 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
|
|||||||
if len(form.Events) == 0 {
|
if len(form.Events) == 0 {
|
||||||
form.Events = []string{"push"}
|
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{
|
w := &webhook.Webhook{
|
||||||
OwnerID: ownerID,
|
OwnerID: ownerID,
|
||||||
RepoID: repoID,
|
RepoID: repoID,
|
||||||
@ -176,6 +186,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, ownerID, repoI
|
|||||||
ContentType: webhook.ToHookContentType(form.Config["content_type"]),
|
ContentType: webhook.ToHookContentType(form.Config["content_type"]),
|
||||||
Secret: form.Config["secret"],
|
Secret: form.Config["secret"],
|
||||||
HTTPMethod: "POST",
|
HTTPMethod: "POST",
|
||||||
|
IsSystemWebhook: isSystemWebhook,
|
||||||
HookEvent: &webhook_module.HookEvent{
|
HookEvent: &webhook_module.HookEvent{
|
||||||
ChooseEvents: true,
|
ChooseEvents: true,
|
||||||
HookEvents: webhook_module.HookEvents{
|
HookEvents: webhook_module.HookEvents{
|
||||||
|
Loading…
Reference in New Issue
Block a user