summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-28 23:36:13 +0800
committerUnknwon <u@gogs.io>2015-08-28 23:36:13 +0800
commitf509c59ac13dffdff6a246572de04150ee295314 (patch)
tree3be3923779cedce3058f28f1d32604226985be03 /routers
parenta541ca16b67d492340ac55b84ff190d2a52fc39d (diff)
downloadgitea-f509c59ac13dffdff6a246572de04150ee295314.tar.gz
gitea-f509c59ac13dffdff6a246572de04150ee295314.zip
new create webhook event
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo_hooks.go4
-rw-r--r--routers/repo/setting.go46
2 files changed, 27 insertions, 23 deletions
diff --git a/routers/api/v1/repo_hooks.go b/routers/api/v1/repo_hooks.go
index 68b4834380..2cb71b1590 100644
--- a/routers/api/v1/repo_hooks.go
+++ b/routers/api/v1/repo_hooks.go
@@ -83,7 +83,7 @@ func CreateRepoHook(ctx *middleware.Context, form api.CreateHookOption) {
ctx.JSON(422, &base.ApiJsonErr{"missing config option: channel", base.DOC_URL})
return
}
- meta, err := json.Marshal(&models.Slack{
+ meta, err := json.Marshal(&models.SlackMeta{
Channel: channel,
})
if err != nil {
@@ -141,7 +141,7 @@ func EditRepoHook(ctx *middleware.Context, form api.EditHookOption) {
if w.HookTaskType == models.SLACK {
if channel, ok := form.Config["channel"]; ok {
- meta, err := json.Marshal(&models.Slack{
+ meta, err := json.Marshal(&models.SlackMeta{
Channel: channel,
})
if err != nil {
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index b463b7c6a1..fc5e1abc92 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -320,6 +320,18 @@ func WebhooksNew(ctx *middleware.Context) {
ctx.HTML(200, orCtx.NewTemplate)
}
+func ParseHookEvent(form auth.WebhookForm) *models.HookEvent {
+ return &models.HookEvent{
+ PushOnly: form.PushOnly(),
+ SendEverything: form.SendEverything(),
+ ChooseEvents: form.ChooseEvents(),
+ HookEvents: models.HookEvents{
+ Create: form.Create,
+ Push: form.Push,
+ },
+ }
+}
+
func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true
@@ -345,13 +357,11 @@ func WebHooksNewPost(ctx *middleware.Context, form auth.NewWebhookForm) {
}
w := &models.Webhook{
- RepoID: orCtx.RepoID,
- URL: form.PayloadURL,
- ContentType: contentType,
- Secret: form.Secret,
- HookEvent: &models.HookEvent{
- PushOnly: form.PushOnly,
- },
+ RepoID: orCtx.RepoID,
+ URL: form.PayloadURL,
+ ContentType: contentType,
+ Secret: form.Secret,
+ HookEvent: ParseHookEvent(form.WebhookForm),
IsActive: form.Active,
HookTaskType: models.GOGS,
OrgID: orCtx.OrgID,
@@ -385,7 +395,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
return
}
- meta, err := json.Marshal(&models.Slack{
+ meta, err := json.Marshal(&models.SlackMeta{
Channel: form.Channel,
})
if err != nil {
@@ -394,12 +404,10 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
}
w := &models.Webhook{
- RepoID: orCtx.RepoID,
- URL: form.PayloadURL,
- ContentType: models.JSON,
- HookEvent: &models.HookEvent{
- PushOnly: form.PushOnly,
- },
+ RepoID: orCtx.RepoID,
+ URL: form.PayloadURL,
+ ContentType: models.JSON,
+ HookEvent: ParseHookEvent(form.WebhookForm),
IsActive: form.Active,
HookTaskType: models.SLACK,
Meta: string(meta),
@@ -491,9 +499,7 @@ func WebHooksEditPost(ctx *middleware.Context, form auth.NewWebhookForm) {
w.URL = form.PayloadURL
w.ContentType = contentType
w.Secret = form.Secret
- w.HookEvent = &models.HookEvent{
- PushOnly: form.PushOnly,
- }
+ w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err)
@@ -523,7 +529,7 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
return
}
- meta, err := json.Marshal(&models.Slack{
+ meta, err := json.Marshal(&models.SlackMeta{
Channel: form.Channel,
})
if err != nil {
@@ -533,9 +539,7 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) {
w.URL = form.PayloadURL
w.Meta = string(meta)
- w.HookEvent = &models.HookEvent{
- PushOnly: form.PushOnly,
- }
+ w.HookEvent = ParseHookEvent(form.WebhookForm)
w.IsActive = form.Active
if err := w.UpdateEvent(); err != nil {
ctx.Handle(500, "UpdateEvent", err)