import (
"encoding/json"
+ "fmt"
"net/http"
"strings"
// 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"} {
// 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
}