[REFACTOR] webhook forgejo/gitea endpoints
This commit is contained in:
parent
8dfbbfef07
commit
7e0965b02c
4 changed files with 22 additions and 76 deletions
|
@ -361,62 +361,6 @@ func editWebhook(ctx *context.Context, params webhookParams) {
|
|||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID))
|
||||
}
|
||||
|
||||
// ForgejoHooksNewPost response for creating Forgejo webhook
|
||||
func ForgejoHooksNewPost(ctx *context.Context) {
|
||||
createWebhook(ctx, forgejoHookParams(ctx))
|
||||
}
|
||||
|
||||
// ForgejoHooksEditPost response for editing Forgejo webhook
|
||||
func ForgejoHooksEditPost(ctx *context.Context) {
|
||||
editWebhook(ctx, forgejoHookParams(ctx))
|
||||
}
|
||||
|
||||
func forgejoHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewWebhookForm)
|
||||
|
||||
contentType := webhook.ContentTypeJSON
|
||||
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm {
|
||||
contentType = webhook.ContentTypeForm
|
||||
}
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.FORGEJO,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: contentType,
|
||||
Secret: form.Secret,
|
||||
HTTPMethod: form.HTTPMethod,
|
||||
WebhookForm: form.WebhookForm,
|
||||
}
|
||||
}
|
||||
|
||||
// GiteaHooksNewPost response for creating Gitea webhook
|
||||
func GiteaHooksNewPost(ctx *context.Context) {
|
||||
createWebhook(ctx, giteaHookParams(ctx))
|
||||
}
|
||||
|
||||
// GiteaHooksEditPost response for editing Gitea webhook
|
||||
func GiteaHooksEditPost(ctx *context.Context) {
|
||||
editWebhook(ctx, giteaHookParams(ctx))
|
||||
}
|
||||
|
||||
func giteaHookParams(ctx *context.Context) webhookParams {
|
||||
form := web.GetForm(ctx).(*forms.NewWebhookForm)
|
||||
|
||||
contentType := webhook.ContentTypeJSON
|
||||
if webhook.HookContentType(form.ContentType) == webhook.ContentTypeForm {
|
||||
contentType = webhook.ContentTypeForm
|
||||
}
|
||||
|
||||
return webhookParams{
|
||||
Type: webhook_module.GITEA,
|
||||
URL: form.PayloadURL,
|
||||
ContentType: contentType,
|
||||
Secret: form.Secret,
|
||||
HTTPMethod: form.HTTPMethod,
|
||||
WebhookForm: form.WebhookForm,
|
||||
}
|
||||
}
|
||||
|
||||
// GogsHooksNewPost response for creating Gogs webhook
|
||||
func GogsHooksNewPost(ctx *context.Context) {
|
||||
createWebhook(ctx, gogsHookParams(ctx))
|
||||
|
|
|
@ -402,8 +402,6 @@ func registerRoutes(m *web.Route) {
|
|||
|
||||
addWebhookAddRoutes := func() {
|
||||
m.Get("/{type}/new", repo_setting.WebhooksNew)
|
||||
m.Post("/forgejo/new", web.Bind(forms.NewWebhookForm{}), repo_setting.ForgejoHooksNewPost)
|
||||
m.Post("/gitea/new", web.Bind(forms.NewWebhookForm{}), repo_setting.GiteaHooksNewPost)
|
||||
m.Post("/gogs/new", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksNewPost)
|
||||
m.Post("/slack/new", web.Bind(forms.NewSlackHookForm{}), repo_setting.SlackHooksNewPost)
|
||||
m.Post("/discord/new", web.Bind(forms.NewDiscordHookForm{}), repo_setting.DiscordHooksNewPost)
|
||||
|
@ -417,8 +415,6 @@ func registerRoutes(m *web.Route) {
|
|||
}
|
||||
|
||||
addWebhookEditRoutes := func() {
|
||||
m.Post("/forgejo/{id}", web.Bind(forms.NewWebhookForm{}), repo_setting.ForgejoHooksEditPost)
|
||||
m.Post("/gitea/{id}", web.Bind(forms.NewWebhookForm{}), repo_setting.GiteaHooksEditPost)
|
||||
m.Post("/gogs/{id}", web.Bind(forms.NewGogshookForm{}), repo_setting.GogsHooksEditPost)
|
||||
m.Post("/slack/{id}", web.Bind(forms.NewSlackHookForm{}), repo_setting.SlackHooksEditPost)
|
||||
m.Post("/discord/{id}", web.Bind(forms.NewDiscordHookForm{}), repo_setting.DiscordHooksEditPost)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue