From 3794111460e8f69a69bfaacade2978fe89644270 Mon Sep 17 00:00:00 2001 From: Christopher Brickley Date: Fri, 24 Oct 2014 08:56:12 -0400 Subject: [PATCH] update slack hook to use new format --- models/slack.go | 10 ---------- modules/auth/repo_form.go | 3 +-- routers/repo/setting.go | 8 ++------ templates/repo/settings/hook_slack.tmpl | 8 ++------ 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/models/slack.go b/models/slack.go index 3dd40759af..0b1b579ff0 100644 --- a/models/slack.go +++ b/models/slack.go @@ -16,8 +16,6 @@ const ( ) type Slack struct { - Domain string `json:"domain"` - Token string `json:"token"` Channel string `json:"channel"` } @@ -36,14 +34,6 @@ type SlackAttachment struct { Text string `json:"text"` } -func GetSlackURL(domain string, token string) string { - return fmt.Sprintf( - "https://%s.slack.com/services/hooks/incoming-webhook?token=%s", - domain, - token, - ) -} - func (p SlackPayload) GetJSONPayload() ([]byte, error) { data, err := json.Marshal(p) if err != nil { diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index 86fbdc4926..7901ce8777 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -81,8 +81,7 @@ func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) bin type NewSlackHookForm struct { HookTaskType string `form:"hook_type" binding:"Required"` - Domain string `form:"domain" binding:"Required` - Token string `form:"token" binding:"Required"` + PayloadUrl string `form:"payload_url" binding:"Required` Channel string `form:"channel" binding:"Required"` PushOnly bool `form:"push_only"` Active bool `form:"active"` diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 971c5bef2a..a8e80272c1 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -483,9 +483,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { } meta, err := json.Marshal(&models.Slack{ - Domain: form.Domain, Channel: form.Channel, - Token: form.Token, }) if err != nil { ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err) @@ -494,7 +492,7 @@ func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { w := &models.Webhook{ RepoId: orCtx.RepoId, - Url: models.GetSlackURL(form.Domain, form.Token), + Url: form.PayloadUrl, ContentType: models.JSON, Secret: "", HookEvent: &models.HookEvent{ @@ -551,16 +549,14 @@ func SlackHooksEditPost(ctx *middleware.Context, form auth.NewSlackHookForm) { return } meta, err := json.Marshal(&models.Slack{ - Domain: form.Domain, Channel: form.Channel, - Token: form.Token, }) if err != nil { ctx.Handle(500, "SlackHooksNewPost: JSON marshal failed: ", err) return } - w.Url = models.GetSlackURL(form.Domain, form.Token) + w.Url = form.PayloadUrl w.Meta = string(meta) w.HookEvent = &models.HookEvent{ PushOnly: form.PushOnly, diff --git a/templates/repo/settings/hook_slack.tmpl b/templates/repo/settings/hook_slack.tmpl index ed7a42e6f7..08d86180e5 100644 --- a/templates/repo/settings/hook_slack.tmpl +++ b/templates/repo/settings/hook_slack.tmpl @@ -4,12 +4,8 @@
{{.i18n.Tr "repo.settings.add_slack_hook_desc" | Str2html}}
- - -
-
- - + +