refactor(besadii): Rename branchUpdate -> refUpdated

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>
This commit is contained in:
Vincent Ambo 2020-06-28 02:11:10 +01:00 committed by tazjin
parent c8e888c1d2
commit d3284112f6

View file

@ -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)