]> source.dussan.org Git - gitea.git/commitdiff
Possible fix the webhook API creation (#13960)
authorLunny Xiao <xiaolunwen@gmail.com>
Sat, 12 Dec 2020 15:33:19 +0000 (23:33 +0800)
committerGitHub <noreply@github.com>
Sat, 12 Dec 2020 15:33:19 +0000 (16:33 +0100)
* Possible fix the webhook API creation

* Fix api create webhook bug

routers/api/v1/utils/hook.go
services/webhook/webhook.go

index c8471184f571a0992cb4ac69960ccd1d71d7933f..8decc5cf4329d13b57c489513fb5b0df1d8f6d88 100644 (file)
@@ -6,6 +6,7 @@ package utils
 
 import (
        "encoding/json"
+       "fmt"
        "net/http"
        "strings"
 
@@ -53,7 +54,7 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*models.Webhook
 // write the appropriate error to `ctx`. Return whether the form is valid
 func CheckCreateHookOption(ctx *context.APIContext, form *api.CreateHookOption) bool {
        if !webhook.IsValidHookTaskType(form.Type) {
-               ctx.Error(http.StatusUnprocessableEntity, "", "Invalid hook type")
+               ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Invalid hook type: %s", form.Type))
                return false
        }
        for _, name := range []string{"url", "content_type"} {
index a86d638ab5057981943cedadf3d503efd44b3187..b779b38466ade6d0f9b0ced68481d1d65e536926 100644 (file)
@@ -60,12 +60,15 @@ var (
 
 // RegisterWebhook registers a webhook
 func RegisterWebhook(name string, webhook *webhook) {
-       webhooks[models.HookTaskType(name)] = webhook
+       webhooks[models.HookTaskType(strings.TrimSpace(name))] = webhook
 }
 
 // IsValidHookTaskType returns true if a webhook registered
 func IsValidHookTaskType(name string) bool {
-       _, ok := webhooks[models.HookTaskType(name)]
+       if name == models.GITEA || name == models.GOGS {
+               return true
+       }
+       _, ok := webhooks[models.HookTaskType(strings.TrimSpace(name))]
        return ok
 }