diff options
author | Åsmund Østvold <asmundo@gmail.com> | 2022-01-07T10·37+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-01-19T10·31+0000 |
commit | 6e4b0f3cef56443a9780c4ff73466556e4915513 (patch) | |
tree | 12d9a7db834f42ebf4717fea969267432afb3039 /ops/besadii/main.go | |
parent | e1146601c117ab398bd85311c8cdfd6ec51a7fa5 (diff) |
feat(ops/besadii): make text 'cl' posted BuildKite configurable r/3633
Some companies do not know the 'cl' term. They do know of 'change' and would maybe not like to introduce one more synonym. This cl introduce an optional entry 'gerritChangeName' in besadii.json. The string has to match `^[a-z0-9]+$` for readability. Change-Id: Id70fcb1e45158869f88bf37669be49b8b8a3b295 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4825 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: asmundo <asmundo@gmail.com>
Diffstat (limited to 'ops/besadii/main.go')
-rw-r--r-- | ops/besadii/main.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/ops/besadii/main.go b/ops/besadii/main.go index c02c2fbc0d0c..e22dbb1e484e 100644 --- a/ops/besadii/main.go +++ b/ops/besadii/main.go @@ -34,6 +34,13 @@ import ( // Regular expression to extract change ID out of a URL var changeIdRegexp = regexp.MustCompile(`^.*/(\d+)$`) +// Regular expression to check if gerritChangeName valid. The +// limitation could be what is allowed for a git branch name. For now +// we want to have a stricter limitation for readability and ease of +// use. +var gerritChangeNameRegexp = `^[a-z0-9]+$` +var gerritChangeNameCheck = regexp.MustCompile(gerritChangeNameRegexp) + // besadii configuration file structure type config struct { // Required configuration for Buildkite<>Gerrit monorepo @@ -47,6 +54,7 @@ type config struct { BuildkiteOrg string `json:"buildkiteOrg"` BuildkiteProject string `json:"buildkiteProject"` BuildkiteToken string `json:"buildkiteToken"` + GerritChangeName string `json:"gerritChangeName"` // Optional configuration for Sourcegraph trigger updates. SourcegraphUrl string `json:"sourcegraphUrl"` @@ -138,6 +146,14 @@ func loadConfig() (*config, error) { cfg.GerritLabel = "Verified" } + // The default text referring to a Gerrit Change in BuildKite. + if cfg.GerritChangeName == "" { + cfg.GerritChangeName = "cl" + } + if !gerritChangeNameCheck.MatchString(cfg.GerritChangeName) { + return nil, fmt.Errorf("invalid 'gerritChangeName': %s", cfg.GerritChangeName) + } + // Rudimentary config validation logic if cfg.SourcegraphUrl != "" && cfg.SourcegraphToken == "" { return nil, fmt.Errorf("'SourcegraphToken' must be set if 'SourcegraphUrl' is set") @@ -180,7 +196,7 @@ func updateGerrit(cfg *config, review reviewInput, changeId, patchset string) { resp, err := http.DefaultClient.Do(req) if err != nil { - fmt.Errorf("failed to update CL on Gerrit: %w", err) + fmt.Errorf("failed to update %s on %s: %w", cfg.GerritChangeName, cfg.GerritUrl, err) } defer resp.Body.Close() @@ -210,8 +226,8 @@ func triggerBuild(cfg *config, log *syslog.Writer, trigger *buildTrigger) error headBuild = false // The branch doesn't have to be a real ref (it's just used to - // group builds), so make it the identifier for the CL - branch = fmt.Sprintf("cl/%v", strings.Split(trigger.ref, "/")[3]) + // group builds), so make it the identifier for the CL. + branch = fmt.Sprintf("%s/%v", cfg.GerritChangeName, strings.Split(trigger.ref, "/")[3]) } build := Build{ @@ -459,7 +475,7 @@ func postCommandMain(cfg *config) { // If these variables are unset, but the hook was invoked, the // build was most likely for a branch and not for a CL - no status // needs to be reported back to Gerrit! - fmt.Println("This isn't a CL build, nothing to do. Have a nice day!") + fmt.Println("This isn't a %s build, nothing to do. Have a nice day!", cfg.GerritChangeName) return } |