From 0af5ba2275016d2998f78008c873baee8eb6f1d1 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Thu, 9 Jun 2022 14:08:23 -0700 Subject: feat(gerrit-hook): propagate gerrit information in the environment The buildKite agents need this information in order to vote after a build. Change-Id: If03ba51d55f4d1155c6b7fdadace3b4643480258 Reviewed-on: https://cl.fcuny.net/c/world/+/342 Reviewed-by: Franck Cuny --- tools/gerrit-hook/buildkite.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'tools') 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) -- cgit 1.4.1