From 297e772c20382afa31ad30ab65827ce0aca58446 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 10 Feb 2016 15:21:39 -0500 Subject: #2485 fix payloads mixed up for webhook When repository contains a Slack type hook, it changes original payload content. This patch fixes it by using a local object to store newly created Slack payload instead of assigning back to the same variable. --- models/webhook.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'models') diff --git a/models/webhook.go b/models/webhook.go index 27ac75fe07..bdfb62d899 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -398,6 +398,7 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err return nil } + var payloader api.Payloader for _, w := range ws { switch event { case HOOK_EVENT_CREATE: @@ -410,14 +411,16 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err } } + // Use separate objects so modifcations won't be made on payload on non-Gogs type hooks. switch w.HookTaskType { case SLACK: - p, err = GetSlackPayload(p, event, w.Meta) + payloader, err = GetSlackPayload(p, event, w.Meta) if err != nil { return fmt.Errorf("GetSlackPayload: %v", err) } default: p.SetSecret(w.Secret) + payloader = p } if err = CreateHookTask(&HookTask{ @@ -425,7 +428,7 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err HookID: w.ID, Type: w.HookTaskType, URL: w.URL, - Payloader: p, + Payloader: payloader, ContentType: w.ContentType, EventType: HOOK_EVENT_PUSH, IsSSL: w.IsSSL, -- cgit v1.2.3