Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System-wide webhooks #10546

Merged
merged 19 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modify router to handle system webhooks and default ones
  • Loading branch information
jamesorlakin committed Mar 1, 2020
commit c35b7acafa1af93764bb6aaef14bce725d859145
26 changes: 19 additions & 7 deletions routers/admin/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@
package admin

import (
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
)

const (
// tplAdminHooks template path for render hook settings
// tplAdminHooks template path to render hook settings
tplAdminHooks base.TplName = "admin/hooks"
)

// DefaultWebhooks render admin-default webhook list page
func DefaultWebhooks(ctx *context.Context) {
// DefaultAndSystemWebhooks renders both admin default and system webhook list pages
func DefaultAndSystemWebhooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.hooks")
ctx.Data["PageIsAdminHooks"] = true
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
ctx.Data["Description"] = ctx.Tr("admin.hooks.desc")

ws, err := models.GetDefaultWebhooks()
// Are we looking at default webhooks?
var ws []*models.Webhook
var err error
if strings.Contains(ctx.Link, "/admin/hooks") {
ctx.Data["PageIsAdminHooks"] = true
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
ws, err = models.GetDefaultWebhooks()
} else {
ctx.Data["PageIsAdminSystemHooks"] = true
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/system-hooks"
ws, err = models.GetSystemWebhooks()
}

if err != nil {
ctx.ServerError("GetWebhooksDefaults", err)
ctx.ServerError("GetWebhooksAdmin", err)
return
}

Expand Down
4 changes: 2 additions & 2 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/delete", admin.DeleteRepo)
})

m.Group("/hooks", func() {
m.Get("", admin.DefaultWebhooks)
m.Group("/^:type(hooks|system-hooks)$", func() {
m.Get("", admin.DefaultAndSystemWebhooks)
m.Post("/delete", admin.DeleteDefaultWebhook)
m.Get("/:type/new", repo.WebhooksNew)
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
Expand Down