Add replay of webhooks. (#18191)
This commit is contained in:
parent
a38ba634a4
commit
bf7b083cfe
8 changed files with 108 additions and 13 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue