diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-05 20:52:25 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-05 20:52:25 -0400 |
commit | 24f614f6db13e5c6720efa518641ffcdcb0d8947 (patch) | |
tree | 523d1d93079bed85b75859b51bff408797ed4aae /routers | |
parent | cb505b22ec5133ffe3263f3857fdcd64fa64260b (diff) | |
download | gitea-24f614f6db13e5c6720efa518641ffcdcb0d8947.tar.gz gitea-24f614f6db13e5c6720efa518641ffcdcb0d8947.zip |
Finish add web hook
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/setting.go | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/routers/repo/setting.go b/routers/repo/setting.go index c308739207..d49c93375b 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -199,18 +199,62 @@ func CollaborationPost(ctx *middleware.Context) { func WebHooks(ctx *middleware.Context) { ctx.Data["IsRepoToolbarWebHooks"] = true - ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Web Hooks" + ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhooks" + + ws, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id) + if err != nil { + ctx.Handle(500, "repo.WebHooks(GetWebhooksByRepoId)", err) + return + } + + ctx.Data["Webhooks"] = ws ctx.HTML(200, "repo/hooks") } func WebHooksAdd(ctx *middleware.Context) { ctx.Data["IsRepoToolbarWebHooks"] = true - ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Add Web Hook" + ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Add Webhook" ctx.HTML(200, "repo/hooks_add") } +func WebHooksAddPost(ctx *middleware.Context, form auth.NewWebhookForm) { + ctx.Data["IsRepoToolbarWebHooks"] = true + ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Add Webhook" + + if ctx.HasError() { + ctx.HTML(200, "repo/hooks_add") + return + } + + ct := models.CT_JSON + if form.ContentType == "form" { + ct = models.CT_FORM + } + + w := &models.Webhook{ + RepoId: ctx.Repo.Repository.Id, + Payload: form.Url, + ContentType: ct, + Secret: form.Secret, + IsActive: form.Active, + } + h := &models.HookEvent{ + PushOnly: form.PushOnly, + } + if err := w.SaveEvent(h); err != nil { + ctx.Handle(500, "repo.WebHooksAddPost(SaveEvent)", err) + return + } else if err := models.CreateWebhook(w); err != nil { + ctx.Handle(500, "repo.WebHooksAddPost(CreateWebhook)", err) + return + } + + ctx.Flash.Success("New webhook has been added.") + ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks") +} + func WebHooksEdit(ctx *middleware.Context) { ctx.Data["IsRepoToolbarWebHooks"] = true - ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Web Hook Name" + ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhook" ctx.HTML(200, "repo/hooks_edit") } |