[REFACTOR] webhook forgejo/gitea endpoints
This commit is contained in:
parent
8dfbbfef07
commit
7e0965b02c
4 changed files with 22 additions and 76 deletions
|
@ -279,21 +279,6 @@ func (f WebhookForm) ChooseEvents() bool {
|
|||
return f.Events == "choose_events"
|
||||
}
|
||||
|
||||
// NewWebhookForm form for creating web hook
|
||||
type NewWebhookForm struct {
|
||||
PayloadURL string `binding:"Required;ValidUrl"`
|
||||
HTTPMethod string `binding:"Required;In(POST,GET)"`
|
||||
ContentType int `binding:"Required"`
|
||||
Secret string
|
||||
WebhookForm
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
}
|
||||
|
||||
// NewGogshookForm form for creating gogs hook
|
||||
type NewGogshookForm struct {
|
||||
PayloadURL string `binding:"Required;ValidUrl"`
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
)
|
||||
|
||||
var _ Handler = defaultHandler{}
|
||||
|
@ -36,7 +37,27 @@ func (dh defaultHandler) Type() webhook_module.HookType {
|
|||
func (defaultHandler) Metadata(*webhook_model.Webhook) any { return nil }
|
||||
|
||||
func (defaultHandler) FormFields(bind func(any)) FormFields {
|
||||
panic("TODO")
|
||||
var form struct {
|
||||
forms.WebhookForm
|
||||
PayloadURL string `binding:"Required;ValidUrl"`
|
||||
HTTPMethod string `binding:"Required;In(POST,GET)"`
|
||||
ContentType int `binding:"Required"`
|
||||
Secret string
|
||||
}
|
||||
bind(&form)
|
||||
|
||||
contentType := webhook_model.ContentTypeJSON
|
||||
if webhook_model.HookContentType(form.ContentType) == webhook_model.ContentTypeForm {
|
||||
contentType = webhook_model.ContentTypeForm
|
||||
}
|
||||
return FormFields{
|
||||
WebhookForm: form.WebhookForm,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: contentType,
|
||||
Secret: form.Secret,
|
||||
HTTPMethod: form.HTTPMethod,
|
||||
Metadata: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (defaultHandler) NewRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (req *http.Request, body []byte, err error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue