[REFACTOR] webhook discord endpoint

This commit is contained in:
oliverpool 2024-03-21 13:54:27 +01:00
parent 6f00821f3d
commit c3f8e6ed60
4 changed files with 20 additions and 42 deletions

View file

@ -292,20 +292,6 @@ func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) bindi
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}
// NewDiscordHookForm form for creating discord hook
type NewDiscordHookForm struct {
PayloadURL string `binding:"Required;ValidUrl"`
Username string
IconURL string
WebhookForm
}
// Validate validates the fields
func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
ctx := context.GetValidateContext(req)
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}
// NewDingtalkHookForm form for creating dingtalk hook
type NewDingtalkHookForm struct {
PayloadURL string `binding:"Required;ValidUrl"`

View file

@ -20,6 +20,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/forms"
)
type discordHandler struct{}
@ -27,7 +28,25 @@ type discordHandler struct{}
func (discordHandler) Type() webhook_module.HookType { return webhook_module.DISCORD }
func (discordHandler) FormFields(bind func(any)) FormFields {
panic("TODO")
var form struct {
forms.WebhookForm
PayloadURL string `binding:"Required;ValidUrl"`
Username string
IconURL string
}
bind(&form)
return FormFields{
WebhookForm: form.WebhookForm,
URL: form.PayloadURL,
ContentType: webhook_model.ContentTypeJSON,
Secret: "",
HTTPMethod: http.MethodPost,
Metadata: &DiscordMeta{
Username: form.Username,
IconURL: form.IconURL,
},
}
}
type (