diff options
author | Vincent Ambo <tazjin@google.com> | 2020-02-21T23·30+0000 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-02-21T23·30+0000 |
commit | a2bb8a7e1dd5a6261eb5e307deace728d3bcaad1 (patch) | |
tree | 16b8ff5bef16db471c6cec4e5bb869c6b6f2407e /ops/besadii/main.go | |
parent | 28560fcf8abc2fa07a0e8ba07c2875bbba33eb02 (diff) |
fix(ops/besadii): Do not trigger builds for deleted branches r/572
Diffstat (limited to 'ops/besadii/main.go')
-rw-r--r-- | ops/besadii/main.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ops/besadii/main.go b/ops/besadii/main.go index d9c27fe31c1d..bf0e707cb693 100644 --- a/ops/besadii/main.go +++ b/ops/besadii/main.go @@ -22,6 +22,11 @@ import ( ) var gitBin = "git" +var branchPrefix = "refs/heads/" + +// This value is set by the git hook invocation when a branch is +// removed, builds should not be triggered in that case. +var deletedBranch = "0000000000000000000000000000000000000000" // Represents an updated reference as passed to besadii by git // @@ -143,15 +148,15 @@ func parseRefUpdates() ([]refUpdate, error) { return nil, fmt.Errorf("invalid ref update: '%s'", line) } - if !strings.HasPrefix(fragments[2], "refs/heads/") { - continue - } - - updates = append(updates, refUpdate{ + update := refUpdate{ old: fragments[0], new: fragments[1], - name: strings.TrimPrefix(fragments[2], "refs/heads/"), - }) + name: strings.TrimPrefix(fragments[2], branchPrefix), + } + + if strings.HasPrefix(update.name, branchPrefix) && update.new != deletedBranch { + updates = append(updates, update) + } } if err := scanner.Err(); err != nil { |