[REFACTOR] webhook wechatwork endpoint
This commit is contained in:
parent
6b719f08d0
commit
36a1d37532
|
@ -388,27 +388,6 @@ func gogsHookParams(ctx *context.Context) webhookParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WechatworkHooksNewPost response for creating Wechatwork webhook
|
|
||||||
func WechatworkHooksNewPost(ctx *context.Context) {
|
|
||||||
createWebhook(ctx, wechatworkHookParams(ctx))
|
|
||||||
}
|
|
||||||
|
|
||||||
// WechatworkHooksEditPost response for editing Wechatwork webhook
|
|
||||||
func WechatworkHooksEditPost(ctx *context.Context) {
|
|
||||||
editWebhook(ctx, wechatworkHookParams(ctx))
|
|
||||||
}
|
|
||||||
|
|
||||||
func wechatworkHookParams(ctx *context.Context) webhookParams {
|
|
||||||
form := web.GetForm(ctx).(*forms.NewWechatWorkHookForm)
|
|
||||||
|
|
||||||
return webhookParams{
|
|
||||||
Type: webhook_module.WECHATWORK,
|
|
||||||
URL: form.PayloadURL,
|
|
||||||
ContentType: webhook.ContentTypeJSON,
|
|
||||||
WebhookForm: form.WebhookForm,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PackagistHooksNewPost response for creating Packagist webhook
|
// PackagistHooksNewPost response for creating Packagist webhook
|
||||||
func PackagistHooksNewPost(ctx *context.Context) {
|
func PackagistHooksNewPost(ctx *context.Context) {
|
||||||
createWebhook(ctx, packagistHookParams(ctx))
|
createWebhook(ctx, packagistHookParams(ctx))
|
||||||
|
|
|
@ -403,14 +403,12 @@ func registerRoutes(m *web.Route) {
|
||||||
addWebhookAddRoutes := func() {
|
addWebhookAddRoutes := func() {
|
||||||
m.Get("/{type}/new", repo_setting.WebhooksNew)
|
m.Get("/{type}/new", repo_setting.WebhooksNew)
|
||||||
m.Post("/gogs/new", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksNewPost)
|
m.Post("/gogs/new", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksNewPost)
|
||||||
m.Post("/wechatwork/new", web.Bind(forms.NewWechatWorkHookForm{}), repo_setting.WechatworkHooksNewPost)
|
|
||||||
m.Post("/packagist/new", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksNewPost)
|
m.Post("/packagist/new", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksNewPost)
|
||||||
m.Post("/{type}/new", repo_setting.WebhookCreate)
|
m.Post("/{type}/new", repo_setting.WebhookCreate)
|
||||||
}
|
}
|
||||||
|
|
||||||
addWebhookEditRoutes := func() {
|
addWebhookEditRoutes := func() {
|
||||||
m.Post("/gogs/{id}", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksEditPost)
|
m.Post("/gogs/{id}", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksEditPost)
|
||||||
m.Post("/wechatwork/{id}", web.Bind(forms.NewWechatWorkHookForm{}), repo_setting.WechatworkHooksEditPost)
|
|
||||||
m.Post("/packagist/{id}", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksEditPost)
|
m.Post("/packagist/{id}", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksEditPost)
|
||||||
m.Post("/{type}/{id:[0-9]+}", repo_setting.WebhookUpdate)
|
m.Post("/{type}/{id:[0-9]+}", repo_setting.WebhookUpdate)
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,18 +292,6 @@ func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) bindi
|
||||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWechatWorkHookForm form for creating wechatwork hook
|
|
||||||
type NewWechatWorkHookForm struct {
|
|
||||||
PayloadURL string `binding:"Required;ValidUrl"`
|
|
||||||
WebhookForm
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate validates the fields
|
|
||||||
func (f *NewWechatWorkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
|
||||||
ctx := context.GetValidateContext(req)
|
|
||||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPackagistHookForm form for creating packagist hook
|
// NewPackagistHookForm form for creating packagist hook
|
||||||
type NewPackagistHookForm struct {
|
type NewPackagistHookForm struct {
|
||||||
Username string `binding:"Required"`
|
Username string `binding:"Required"`
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||||
|
"code.gitea.io/gitea/services/forms"
|
||||||
)
|
)
|
||||||
|
|
||||||
type wechatworkHandler struct{}
|
type wechatworkHandler struct{}
|
||||||
|
@ -21,7 +22,20 @@ func (wechatworkHandler) Type() webhook_module.HookType { return webhook_m
|
||||||
func (wechatworkHandler) Metadata(*webhook_model.Webhook) any { return nil }
|
func (wechatworkHandler) Metadata(*webhook_model.Webhook) any { return nil }
|
||||||
|
|
||||||
func (wechatworkHandler) FormFields(bind func(any)) FormFields {
|
func (wechatworkHandler) FormFields(bind func(any)) FormFields {
|
||||||
panic("TODO")
|
var form struct {
|
||||||
|
forms.WebhookForm
|
||||||
|
PayloadURL string `binding:"Required;ValidUrl"`
|
||||||
|
}
|
||||||
|
bind(&form)
|
||||||
|
|
||||||
|
return FormFields{
|
||||||
|
WebhookForm: form.WebhookForm,
|
||||||
|
URL: form.PayloadURL,
|
||||||
|
ContentType: webhook_model.ContentTypeJSON,
|
||||||
|
Secret: "",
|
||||||
|
HTTPMethod: http.MethodPost,
|
||||||
|
Metadata: nil,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
Loading…
Reference in a new issue