Skip to content

Commit 9f100a4

Browse files
authored
Possible fix the webhook API creation (#13960)
* Possible fix the webhook API creation * Fix api create webhook bug
1 parent 6074e13 commit 9f100a4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

routers/api/v1/utils/hook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package utils
66

77
import (
88
"encoding/json"
9+
"fmt"
910
"net/http"
1011
"strings"
1112

@@ -53,7 +54,7 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*models.Webhook
5354
// write the appropriate error to `ctx`. Return whether the form is valid
5455
func CheckCreateHookOption(ctx *context.APIContext, form *api.CreateHookOption) bool {
5556
if !webhook.IsValidHookTaskType(form.Type) {
56-
ctx.Error(http.StatusUnprocessableEntity, "", "Invalid hook type")
57+
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Invalid hook type: %s", form.Type))
5758
return false
5859
}
5960
for _, name := range []string{"url", "content_type"} {

services/webhook/webhook.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ var (
6060

6161
// RegisterWebhook registers a webhook
6262
func RegisterWebhook(name string, webhook *webhook) {
63-
webhooks[models.HookTaskType(name)] = webhook
63+
webhooks[models.HookTaskType(strings.TrimSpace(name))] = webhook
6464
}
6565

6666
// IsValidHookTaskType returns true if a webhook registered
6767
func IsValidHookTaskType(name string) bool {
68-
_, ok := webhooks[models.HookTaskType(name)]
68+
if name == models.GITEA || name == models.GOGS {
69+
return true
70+
}
71+
_, ok := webhooks[models.HookTaskType(strings.TrimSpace(name))]
6972
return ok
7073
}
7174

0 commit comments

Comments
 (0)