Skip to content

Commit

Permalink
cmd/cueckoo: start using basic auth for gerrit as well
Browse files Browse the repository at this point in the history
Just like we do with GitHub via git's credentials,
so that runtrybot can work on CLs on private repositores.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ia9ba8d90348fde2b646e21f31dc252540928d3b1
Reviewed-on: https://review.gerrithub.io/c/cue-sh/tools/+/557240
Reviewed-by: Paul Jolly <paul@myitcv.io>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mvdan committed Aug 3, 2023
1 parent 7b925b4 commit caf725e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/cueckoo/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,20 @@ func loadConfig(ctx context.Context) (*config, error) {
githubAuth := github.BasicAuthTransport{Username: githubUser, Password: githubPassword}
res.githubClient = github.NewClient(githubAuth.Client())

gerritUser, gerritPassword, err := gitCredentials(ctx, gerritURL)
if gerritUser == "" || gerritPassword == "" || err != nil {
// Fall back to the manual env vars.
gerritUser = os.Getenv("GERRIT_USER")
gerritPassword = os.Getenv("GERRIT_PASSWORD")
if gerritUser == "" || gerritPassword == "" {
return nil, fmt.Errorf("configure a git credential helper or set GERRIT_USER and GERRIT_PASSWORD")
}
}
res.gerritClient, err = gerrit.NewClient(res.gerritURL, nil)
if err != nil {
return nil, err
}
res.gerritClient.Authentication.SetBasicAuth(gerritUser, gerritPassword)

return &res, nil
}
Expand Down

0 comments on commit caf725e

Please sign in to comment.