about summary refs log tree commit diff
path: root/ops/besadii
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-12-19T16·14+0300
committertazjin <mail@tazj.in>2021-12-19T16·27+0000
commit3a2a5ffa9d77e12960ba0349e1810efb068f0701 (patch)
tree50a268ca274567a44d8f8a0c6d1a566abc13f80d /ops/besadii
parentb075b1df9de2af1f3880857595d2f53c5a830e0a (diff)
feat(ops/besadii): Pass Gerrit link to builds as an envvar r/3304
This makes it possible to annotate builds with a link back to Gerrit.

Change-Id: If351785d3b631b96753d41f417ca94bc7a95ac54
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4441
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'ops/besadii')
-rw-r--r--ops/besadii/main.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/ops/besadii/main.go b/ops/besadii/main.go
index e051bb367e34..5c9baf6bf530 100644
--- a/ops/besadii/main.go
+++ b/ops/besadii/main.go
@@ -158,6 +158,11 @@ func loadConfig() (*config, error) {
 	return &cfg, nil
 }
 
+// linkToChange creates the full link to a change's patchset in Gerrit
+func linkToChange(cfg *config, changeId, patchset string) string {
+	return path.Join(cfg.GerritUrl, "c", cfg.Repository, "+", changeId, patchset)
+}
+
 // updateGerrit posts a comment on a Gerrit CL to indicate the current build status.
 func updateGerrit(cfg *config, review reviewInput, changeId, patchset string) {
 	body, _ := json.Marshal(review)
@@ -183,7 +188,7 @@ func updateGerrit(cfg *config, review reviewInput, changeId, patchset string) {
 		respBody, _ := ioutil.ReadAll(resp.Body)
 		fmt.Fprintf(os.Stderr, "received non-success response from Gerrit: %s (%v)", respBody, resp.Status)
 	} else {
-		fmt.Printf("Added CI status comment on %s/c/%s/+/%s/%s", cfg.GerritUrl, cfg.Repository, changeId, patchset)
+		fmt.Printf("Added CI status comment on %s", linkToChange(cfg, changeId, patchset))
 	}
 }
 
@@ -198,6 +203,7 @@ func triggerBuild(cfg *config, log *syslog.Writer, trigger *buildTrigger) error
 	// to communicate the build status back to Gerrit.
 	headBuild := true
 	if trigger.changeId != "" && trigger.patchset != "" {
+		env["GERRIT_CHANGE_URL"] = linkToChange(cfg, trigger.changeId, trigger.patchset)
 		env["GERRIT_CHANGE_ID"] = trigger.changeId
 		env["GERRIT_PATCHSET"] = trigger.patchset
 		headBuild = false