1
0
Fork 0
forked from forgejo/forgejo

[REFACTOR] webhook slack endpoints

This commit is contained in:
oliverpool 2024-03-21 13:51:35 +01:00
parent 7e0965b02c
commit 6f00821f3d
4 changed files with 44 additions and 54 deletions

View file

@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/webhook"
"gitea.com/go-chi/binding"
)
@ -293,29 +292,6 @@ func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) bindi
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}
// NewSlackHookForm form for creating slack hook
type NewSlackHookForm struct {
PayloadURL string `binding:"Required;ValidUrl"`
Channel string `binding:"Required"`
Username string
IconURL string
Color string
WebhookForm
}
// Validate validates the fields
func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
ctx := context.GetValidateContext(req)
if !webhook.IsValidSlackChannel(strings.TrimSpace(f.Channel)) {
errs = append(errs, binding.Error{
FieldNames: []string{"Channel"},
Classification: "",
Message: ctx.Locale.TrString("repo.settings.add_webhook.invalid_channel_name"),
})
}
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}
// NewDiscordHookForm form for creating discord hook
type NewDiscordHookForm struct {
PayloadURL string `binding:"Required;ValidUrl"`