about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-06-28T01·11+0100
committertazjin <mail@tazj.in>2020-06-28T17·20+0000
commitd3284112f63d9b3ed137c50e04973dc9d4e4e478 (patch)
tree8c849ac1c5b36925f968a0dbc9245c1ed8ad2e26
parentc8e888c1d2c6dfe60a835d1810ab57d87d097e93 (diff)
refactor(besadii): Rename branchUpdate -> refUpdated r/1105
The name of the hook this type represents is 'refUpdated'. Since we're
adding support for additional hooks, it makes sense to to rename this
accordingly.

Change-Id: Ia568c85493813f5e754c77d0b993aaf246d3d595
Reviewed-on: https://cl.tvl.fyi/c/depot/+/667
Reviewed-by: lukegb <lukegb@tvl.fyi>
-rw-r--r--ops/besadii/main.go215
1 files changed, 8 insertions, 7 deletions
diff --git a/ops/besadii/main.go2 b/ops/besadii/main.go2
index a45d183cdf..1a1dacced8 100644
--- a/ops/besadii/main.go2
+++ b/ops/besadii/main.go2
@@ -23,10 +23,11 @@ import (
 
 var branchPrefix = "refs/heads/"
 
-// Represents an updated branch, as passed to besadii by Gerrit.
+// refUpdated is a struct representing the information passed to
+// besadii when it is invoked as Gerrit's refUpdated hook.
 //
 // https://gerrit.googlesource.com/plugins/hooks/+/HEAD/src/main/resources/Documentation/hooks.md#ref_updated
-type branchUpdate struct {
+type refUpdated struct {
 	project   string
 	branch    string
 	commit    string
@@ -49,7 +50,7 @@ type Build struct {
 }
 
 // Trigger a build of a given branch & commit on Buildkite
-func triggerBuild(log *syslog.Writer, token string, update *branchUpdate) error {
+func triggerBuild(log *syslog.Writer, token string, update *refUpdated) error {
 	build := Build{
 		Commit:  update.commit,
 		Branch:  update.branch,
@@ -103,12 +104,12 @@ func triggerIndexUpdate(token string) error {
 	return err
 }
 
-func branchUpdateFromFlags() (*branchUpdate, error) {
+func refUpdatedFromFlags() (*refUpdated, error) {
 	if path.Base(os.Args[0]) != "ref-updated" {
 		return nil, fmt.Errorf("besadii must be invoked as the 'ref-updated' hook")
 	}
 
-	var update branchUpdate
+	var update refUpdated
 
 	flag.StringVar(&update.project, "project", "", "Gerrit project")
 	flag.StringVar(&update.commit, "newrev", "", "new revision")
@@ -139,7 +140,7 @@ func branchUpdateFromFlags() (*branchUpdate, error) {
 	}
 
 	if !strings.HasPrefix(*ref, branchPrefix) {
-		return nil, fmt.Errorf("besadii only supports branch updates at the moment")
+		return nil, fmt.Errorf("besadii only supports branch updates at the moment (got %q)", *ref)
 	}
 
 	update.branch = strings.TrimPrefix(*ref, branchPrefix)
@@ -166,7 +167,7 @@ func main() {
 		os.Exit(1)
 	}
 
-	update, err := branchUpdateFromFlags()
+	update, err := refUpdatedFromFlags()
 	if err != nil {
 		log.Err(fmt.Sprintf("failed to parse ref update: %s", err))
 		os.Exit(1)