diff options
author | Unknwon <u@gogs.io> | 2015-08-26 21:45:51 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-26 21:45:51 +0800 |
commit | 28814564212b7c64136cc3eda3774af56983557e (patch) | |
tree | c0ea1c8ecb6504241a1d2b4111075ee2b0905470 /routers | |
parent | 1cb03135b745675e614b0b89ab3fde412276fec1 (diff) | |
download | gitea-28814564212b7c64136cc3eda3774af56983557e.tar.gz gitea-28814564212b7c64136cc3eda3774af56983557e.zip |
new webhooks list UI
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo_hooks.go | 14 | ||||
-rw-r--r-- | routers/org/setting.go | 16 | ||||
-rw-r--r-- | routers/repo/setting.go | 56 |
3 files changed, 51 insertions, 35 deletions
diff --git a/routers/api/v1/repo_hooks.go b/routers/api/v1/repo_hooks.go index 0348c68391..eb1c4be447 100644 --- a/routers/api/v1/repo_hooks.go +++ b/routers/api/v1/repo_hooks.go @@ -26,7 +26,7 @@ func ListRepoHooks(ctx *middleware.Context) { apiHooks := make([]*api.Hook, len(hooks)) for i := range hooks { h := &api.Hook{ - Id: hooks[i].Id, + ID: hooks[i].ID, Type: hooks[i].HookTaskType.Name(), Active: hooks[i].IsActive, Config: make(map[string]string), @@ -35,7 +35,7 @@ func ListRepoHooks(ctx *middleware.Context) { // Currently, onle have push event. h.Events = []string{"push"} - h.Config["url"] = hooks[i].Url + h.Config["url"] = hooks[i].URL h.Config["content_type"] = hooks[i].ContentType.Name() if hooks[i].HookTaskType == models.SLACK { s := hooks[i].GetSlackHook() @@ -67,8 +67,8 @@ func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) { } w := &models.Webhook{ - RepoId: ctx.Repo.Repository.ID, - Url: form.Config["url"], + RepoID: ctx.Repo.Repository.ID, + URL: form.Config["url"], ContentType: models.ToHookContentType(form.Config["content_type"]), Secret: form.Config["secret"], HookEvent: &models.HookEvent{ @@ -102,12 +102,12 @@ func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) { } apiHook := &api.Hook{ - Id: w.Id, + ID: w.ID, Type: w.HookTaskType.Name(), Events: []string{"push"}, Active: w.IsActive, Config: map[string]string{ - "url": w.Url, + "url": w.URL, "content_type": w.ContentType.Name(), }, } @@ -129,7 +129,7 @@ func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) { if form.Config != nil { if url, ok := form.Config["url"]; ok { - w.Url = url + w.URL = url } if ct, ok := form.Config["content_type"]; ok { if !models.IsValidHookContentType(ct) { diff --git a/routers/org/setting.go b/routers/org/setting.go index 7a76199502..a15af26d43 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -105,9 +105,11 @@ func SettingsDelete(ctx *middleware.Context) { ctx.HTML(200, SETTINGS_DELETE) } -func SettingsHooks(ctx *middleware.Context) { +func Webhooks(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsHooks"] = true + ctx.Data["BaseLink"] = ctx.Org.OrgLink + ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc") // Delete web hook. remove := com.StrTo(ctx.Query("remove")).MustInt64() @@ -130,3 +132,15 @@ func SettingsHooks(ctx *middleware.Context) { ctx.Data["Webhooks"] = ws ctx.HTML(200, SETTINGS_HOOKS) } + +func DeleteWebhook(ctx *middleware.Context) { + if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil { + ctx.Flash.Error("DeleteWebhook: " + err.Error()) + } else { + ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) + } + + ctx.JSON(200, map[string]interface{}{ + "redirect": ctx.Org.OrgLink + "/settings/hooks", + }) +} diff --git a/routers/repo/setting.go b/routers/repo/setting.go index dfcf598188..8031135ec6 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -173,7 +173,7 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) { } } -func SettingsCollaboration(ctx *middleware.Context) { +func Collaboration(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsCollaboration"] = true @@ -249,26 +249,16 @@ func SettingsCollaboration(ctx *middleware.Context) { func Webhooks(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsHooks"] = true - - // Delete web hook. - remove := com.StrTo(ctx.Query("remove")).MustInt64() - if remove > 0 { - if err := models.DeleteWebhook(remove); err != nil { - ctx.Handle(500, "DeleteWebhook", err) - return - } - ctx.Flash.Success(ctx.Tr("repo.settings.remove_hook_success")) - ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks") - return - } + ctx.Data["BaseLink"] = ctx.Repo.RepoLink + ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "http://gogs.io/docs/features/webhook.html") ws, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.ID) if err != nil { ctx.Handle(500, "GetWebhooksByRepoId", err) return } - ctx.Data["Webhooks"] = ws + ctx.HTML(200, HOOKS) } @@ -318,8 +308,8 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { } w := &models.Webhook{ - RepoId: orCtx.RepoId, - Url: form.PayloadUrl, + RepoID: orCtx.RepoId, + URL: form.PayloadUrl, ContentType: ct, Secret: form.Secret, HookEvent: &models.HookEvent{ @@ -328,7 +318,7 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) { IsActive: form.Active, HookTaskType: models.GOGS, Meta: "", - OrgId: orCtx.OrgId, + OrgID: orCtx.OrgId, } if err := w.UpdateEvent(); err != nil { @@ -429,7 +419,7 @@ func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) { ct = models.FORM } - w.Url = form.PayloadUrl + w.URL = form.PayloadUrl w.ContentType = ct w.Secret = form.Secret w.HookEvent = &models.HookEvent{ @@ -474,8 +464,8 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { } w := &models.Webhook{ - RepoId: orCtx.RepoId, - Url: form.PayloadUrl, + RepoID: orCtx.RepoId, + URL: form.PayloadUrl, ContentType: models.JSON, Secret: "", HookEvent: &models.HookEvent{ @@ -484,7 +474,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { IsActive: form.Active, HookTaskType: models.SLACK, Meta: string(meta), - OrgId: orCtx.OrgId, + OrgID: orCtx.OrgId, } if err := w.UpdateEvent(); err != nil { ctx.Handle(500, "UpdateEvent", err) @@ -539,7 +529,7 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { return } - w.Url = form.PayloadUrl + w.URL = form.PayloadUrl w.Meta = string(meta) w.HookEvent = &models.HookEvent{ PushOnly: form.PushOnly, @@ -557,6 +547,18 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, hookId)) } +func DeleteWebhook(ctx *middleware.Context) { + if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil { + ctx.Flash.Error("DeleteWebhook: " + err.Error()) + } else { + ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) + } + + ctx.JSON(200, map[string]interface{}{ + "redirect": ctx.Repo.RepoLink + "/settings/hooks", + }) +} + type OrgRepoCtx struct { OrgId int64 RepoId int64 @@ -608,7 +610,7 @@ func TriggerHook(ctx *middleware.Context) { models.HookQueue.AddRepoID(repo.ID) } -func SettingsGitHooks(ctx *middleware.Context) { +func GitHooks(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsGitHooks"] = true @@ -622,7 +624,7 @@ func SettingsGitHooks(ctx *middleware.Context) { ctx.HTML(200, GITHOOKS) } -func SettingsGitHooksEdit(ctx *middleware.Context) { +func GitHooksEdit(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsGitHooks"] = true @@ -640,7 +642,7 @@ func SettingsGitHooksEdit(ctx *middleware.Context) { ctx.HTML(200, GITHOOK_EDIT) } -func SettingsGitHooksEditPost(ctx *middleware.Context) { +func GitHooksEditPost(ctx *middleware.Context) { name := ctx.Params(":name") hook, err := ctx.Repo.GitRepo.GetHook(name) if err != nil { @@ -659,7 +661,7 @@ func SettingsGitHooksEditPost(ctx *middleware.Context) { ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git") } -func SettingsDeployKeys(ctx *middleware.Context) { +func DeployKeys(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsKeys"] = true @@ -673,7 +675,7 @@ func SettingsDeployKeys(ctx *middleware.Context) { ctx.HTML(200, DEPLOY_KEYS) } -func SettingsDeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { +func DeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsKeys"] = true |