diff options
author | oliverpool <git@olivier.pfad.fr> | 2024-03-21 13:42:40 +0100 |
---|---|---|
committer | oliverpool <git@olivier.pfad.fr> | 2024-03-27 15:38:38 +0100 |
commit | 7e0965b02c8cf9ecb14cdaeaeec7b1612010a603 (patch) | |
tree | 494cdba229254325d4f59fdcb9851bb601891b43 /routers | |
parent | [REFACTOR] webhook matrix endpoints (diff) | |
download | forgejo-7e0965b02c8cf9ecb14cdaeaeec7b1612010a603.tar.xz forgejo-7e0965b02c8cf9ecb14cdaeaeec7b1612010a603.zip |
[REFACTOR] webhook forgejo/gitea endpoints
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/setting/webhook.go | 56 | ||||
-rw-r--r-- | routers/web/web.go | 4 |
2 files changed, 0 insertions, 60 deletions
diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index f41752e470..8900942190 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -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)) diff --git a/routers/web/web.go b/routers/web/web.go index b23068a29d..06ef485422 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -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) |