diff options
author | Daniel Grier <daniel.grier@gmail.com> | 2019-04-20 00:18:06 +1000 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-04-19 10:18:06 -0400 |
commit | b9d1fb6de32613ada3869d2a9692cb078ed48534 (patch) | |
tree | e02d62ed2bbe2c92cad02ef405316507dc8d120b /routers/repo | |
parent | 2af67f6044af1cad7136ce8c123e37ab090ca9bc (diff) | |
download | gitea-b9d1fb6de32613ada3869d2a9692cb078ed48534.tar.gz gitea-b9d1fb6de32613ada3869d2a9692cb078ed48534.zip |
Add support for MS Teams webhooks (#6632)
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/webhook.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index bad109cd53..6cf636f247 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -380,6 +380,46 @@ func TelegramHooksNewPost(ctx *context.Context, form auth.NewTelegramHookForm) { ctx.Redirect(orCtx.Link) } +// MSTeamsHooksNewPost response for creating MS Teams hook +func MSTeamsHooksNewPost(ctx *context.Context, form auth.NewMSTeamsHookForm) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsHooks"] = true + ctx.Data["PageIsSettingsHooksNew"] = true + ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} + + orCtx, err := getOrgRepoCtx(ctx) + if err != nil { + ctx.ServerError("getOrgRepoCtx", err) + return + } + + if ctx.HasError() { + ctx.HTML(200, orCtx.NewTemplate) + return + } + + w := &models.Webhook{ + RepoID: orCtx.RepoID, + URL: form.PayloadURL, + ContentType: models.ContentTypeJSON, + HookEvent: ParseHookEvent(form.WebhookForm), + IsActive: form.Active, + HookTaskType: models.MSTEAMS, + Meta: "", + OrgID: orCtx.OrgID, + } + if err := w.UpdateEvent(); err != nil { + ctx.ServerError("UpdateEvent", err) + return + } else if err := models.CreateWebhook(w); err != nil { + ctx.ServerError("CreateWebhook", err) + return + } + + ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) + ctx.Redirect(orCtx.Link) +} + // SlackHooksNewPost response for creating slack hook func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) { ctx.Data["Title"] = ctx.Tr("repo.settings") @@ -738,6 +778,38 @@ func TelegramHooksEditPost(ctx *context.Context, form auth.NewTelegramHookForm) ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) } +// MSTeamsHooksEditPost response for editing MS Teams hook +func MSTeamsHooksEditPost(ctx *context.Context, form auth.NewMSTeamsHookForm) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsHooks"] = true + ctx.Data["PageIsSettingsHooksEdit"] = true + + orCtx, w := checkWebhook(ctx) + if ctx.Written() { + return + } + ctx.Data["Webhook"] = w + + if ctx.HasError() { + ctx.HTML(200, orCtx.NewTemplate) + return + } + + w.URL = form.PayloadURL + w.HookEvent = ParseHookEvent(form.WebhookForm) + w.IsActive = form.Active + if err := w.UpdateEvent(); err != nil { + ctx.ServerError("UpdateEvent", err) + return + } else if err := models.UpdateWebhook(w); err != nil { + ctx.ServerError("UpdateWebhook", err) + return + } + + ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) + ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) +} + // TestWebhook test if web hook is work fine func TestWebhook(ctx *context.Context) { hookID := ctx.ParamsInt64(":id") |