about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tools/gerrit-hook/buildkite.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/tools/gerrit-hook/buildkite.go b/tools/gerrit-hook/buildkite.go
index 35ad31c..07d2cfd 100644
--- a/tools/gerrit-hook/buildkite.go
+++ b/tools/gerrit-hook/buildkite.go
@@ -9,13 +9,15 @@ import (
 	"log/syslog"
 	"net/http"
 	"os"
+	"strings"
 	"time"
 )
 
 // https://buildkite.com/docs/apis/rest-api/builds#create-a-Build
 type Build struct {
-	Commit string `json:"commit"`
-	Branch string `json:"branch"`
+	Commit string            `json:"commit"`
+	Branch string            `json:"branch"`
+	Env    map[string]string `json:"env"`
 }
 
 type buildResponse struct {
@@ -23,9 +25,21 @@ type buildResponse struct {
 }
 
 func triggerBuild(cfg *config, log *syslog.Writer, trigger *buildTrigger) error {
+	env := make(map[string]string)
+	branch := trigger.ref
+
+	if trigger.changeId != "" && trigger.patchset != "" {
+		env["GERRIT_CHANGE_ID"] = trigger.changeId
+		env["GERRIT_CHANGE_URL"] = trigger.changeUrl
+		env["GERRIT_PATCHSET"] = trigger.patchset
+
+		branch = fmt.Sprintf("cl/%v", strings.Split(trigger.ref, "/")[3])
+	}
+
 	b := Build{
 		Commit: trigger.commit,
-		Branch: trigger.ref,
+		Branch: branch,
+		Env:    env,
 	}
 
 	body, _ := json.Marshal(b)