diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-01-05 22:00:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-05 15:00:20 -0600 |
commit | bf7b083cfe47cc922090ce7922b89f7a5030a44d (patch) | |
tree | 62291bc31a1dd28252a8802555d09085d30416ee /routers | |
parent | a38ba634a4da15fbb2d1b6ac6742cf01c1503ea4 (diff) | |
download | gitea-bf7b083cfe47cc922090ce7922b89f7a5030a44d.tar.gz gitea-bf7b083cfe47cc922090ce7922b89f7a5030a44d.zip |
Add replay of webhooks. (#18191)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/web/repo/webhook.go | 24 | ||||
-rw-r--r-- | routers/web/web.go | 17 |
2 files changed, 36 insertions, 5 deletions
diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go index 47d8413671..2ec2e8911f 100644 --- a/routers/web/repo/webhook.go +++ b/routers/web/repo/webhook.go @@ -1189,11 +1189,33 @@ func TestWebhook(ctx *context.Context) { ctx.Flash.Error("PrepareWebhook: " + err.Error()) ctx.Status(500) } else { - ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success")) + ctx.Flash.Info(ctx.Tr("repo.settings.webhook.delivery.success")) ctx.Status(200) } } +// ReplayWebhook replays a webhook +func ReplayWebhook(ctx *context.Context) { + hookTaskUUID := ctx.Params(":uuid") + + orCtx, w := checkWebhook(ctx) + if ctx.Written() { + return + } + + if err := webhook_service.ReplayHookTask(w, hookTaskUUID); err != nil { + if webhook.IsErrHookTaskNotExist(err) { + ctx.NotFound("ReplayHookTask", nil) + } else { + ctx.ServerError("ReplayHookTask", err) + } + return + } + + ctx.Flash.Success(ctx.Tr("repo.settings.webhook.delivery.success")) + ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) +} + // DeleteWebhook delete a webhook func DeleteWebhook(ctx *context.Context) { if err := webhook.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil { diff --git a/routers/web/web.go b/routers/web/web.go index e35ccb5aab..8abdf7c61f 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -435,7 +435,10 @@ func RegisterRoutes(m *web.Route) { m.Group("/hooks", func() { m.Get("", admin.DefaultOrSystemWebhooks) m.Post("/delete", admin.DeleteDefaultOrSystemWebhook) - m.Get("/{id}", repo.WebHooksEdit) + m.Group("/{id}", func() { + m.Get("", repo.WebHooksEdit) + m.Post("/replay/{uuid}", repo.ReplayWebhook) + }) m.Post("/gitea/{id}", bindIgnErr(forms.NewWebhookForm{}), repo.WebHooksEditPost) m.Post("/gogs/{id}", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksEditPost) m.Post("/slack/{id}", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksEditPost) @@ -559,7 +562,10 @@ func RegisterRoutes(m *web.Route) { m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost) m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost) m.Post("/wechatwork/new", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksNewPost) - m.Get("/{id}", repo.WebHooksEdit) + m.Group("/{id}", func() { + m.Get("", repo.WebHooksEdit) + m.Post("/replay/{uuid}", repo.ReplayWebhook) + }) m.Post("/gitea/{id}", bindIgnErr(forms.NewWebhookForm{}), repo.WebHooksEditPost) m.Post("/gogs/{id}", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksEditPost) m.Post("/slack/{id}", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksEditPost) @@ -653,8 +659,11 @@ func RegisterRoutes(m *web.Route) { m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost) m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost) m.Post("/wechatwork/new", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksNewPost) - m.Get("/{id}", repo.WebHooksEdit) - m.Post("/{id}/test", repo.TestWebhook) + m.Group("/{id}", func() { + m.Get("", repo.WebHooksEdit) + m.Post("/test", repo.TestWebhook) + m.Post("/replay/{uuid}", repo.ReplayWebhook) + }) m.Post("/gitea/{id}", bindIgnErr(forms.NewWebhookForm{}), repo.WebHooksEditPost) m.Post("/gogs/{id}", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksEditPost) m.Post("/slack/{id}", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksEditPost) |