Browse Source

#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.
Unknwon 9 years ago
parent
commit
297e772c20
6 changed files with 9 additions and 6 deletions
  1. 1 1
      .bra.toml
  2. 1 1
      README.md
  3. 1 1
      gogs.go
  4. 5 2
      models/webhook.go
  5. 0 0
      modules/bindata/bindata.go
  6. 1 1
      templates/.VERSION

+ 1 - 1
.bra.toml

@@ -13,7 +13,7 @@ watch_dirs = [
 watch_exts = [".go"]
 build_delay = 1500
 cmds = [
-	["go", "install", "-v", "-race"], # sqlite redis memcache cert pam tidb
+	["go", "install", "-v", "-race"], # sqlite cert pam tidb
 	["go", "build", "-race"],
 	["./gogs", "web"]
 ]

+ 1 - 1
README.md

@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
 
 ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
 
-##### Current version: 0.8.32
+##### Current version: 0.8.33
 
 | Web | UI  | Preview  |
 |:-------------:|:-------:|:-------:|

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
 	"github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.8.32.0207"
+const APP_VER = "0.8.33.0210"
 
 func init() {
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 5 - 2
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,

File diff suppressed because it is too large
+ 0 - 0
modules/bindata/bindata.go


+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.8.32.0207
+0.8.33.0210

Some files were not shown because too many files changed in this diff