feat(besadii): Make Gerrit label configurable

By default besadii will set the `Verified` label in Gerrit. This adds
a config option to set a different label instead if desired.

Co-authored-by: Vincent Ambo <mail@tazj.in>
Change-Id: I254159e46994e01182987ed5e5e26e27c57f46ce
This commit is contained in:
Åsmund Østvold 2021-12-13 11:32:40 +01:00
parent 0286d63df7
commit 6842e25f14

View file

@ -42,6 +42,7 @@ type config struct {
GerritUrl string `json:"gerritUrl"` GerritUrl string `json:"gerritUrl"`
GerritUser string `json:"gerritUser"` GerritUser string `json:"gerritUser"`
GerritPassword string `json:"gerritPassword"` GerritPassword string `json:"gerritPassword"`
GerritLabel string `json:"gerritLabel"`
BuildkiteOrg string `json:"buildkiteOrg"` BuildkiteOrg string `json:"buildkiteOrg"`
BuildkiteProject string `json:"buildkiteProject"` BuildkiteProject string `json:"buildkiteProject"`
BuildkiteToken string `json:"buildkiteToken"` BuildkiteToken string `json:"buildkiteToken"`
@ -130,6 +131,11 @@ func loadConfig() (*config, error) {
return nil, fmt.Errorf("failed to unmarshal besadii config: %w", err) return nil, fmt.Errorf("failed to unmarshal besadii config: %w", err)
} }
// The default Gerrit label to set is 'Verified', unless specified otherwise.
if cfg.GerritLabel == "" {
cfg.GerritLabel = "Verified"
}
// Rudimentary config validation logic // Rudimentary config validation logic
if cfg.SourcegraphUrl != "" && cfg.SourcegraphToken == "" { if cfg.SourcegraphUrl != "" && cfg.SourcegraphToken == "" {
return nil, fmt.Errorf("'SourcegraphToken' must be set if 'SourcegraphUrl' is set") return nil, fmt.Errorf("'SourcegraphToken' must be set if 'SourcegraphUrl' is set")
@ -441,14 +447,14 @@ func postCommandMain(cfg *config) {
return return
} }
var verified int var vote int
var verb string var verb string
if os.Getenv("BUILDKITE_COMMAND_EXIT_STATUS") == "0" { if os.Getenv("BUILDKITE_COMMAND_EXIT_STATUS") == "0" {
verified = 1 // Verified: +1 in Gerrit vote = 1 // automation passed: +1 in Gerrit
verb = "passed" verb = "passed"
} else { } else {
verified = -1 vote = -1
verb = "failed" verb = "failed"
} }
@ -457,11 +463,11 @@ func postCommandMain(cfg *config) {
Message: msg, Message: msg,
OmitDuplicateComments: true, OmitDuplicateComments: true,
Labels: map[string]int{ Labels: map[string]int{
"Verified": verified, cfg.GerritLabel: vote,
}, },
// Update the attention set if we are failing this patchset. // Update the attention set if we are failing this patchset.
IgnoreDefaultAttentionSetRules: verified == 1, IgnoreDefaultAttentionSetRules: vote == 1,
Tag: "autogenerated:buildkite~result", Tag: "autogenerated:buildkite~result",
} }