Skip to content

Commit

Permalink
cmd/cueckoo: swap x/build/gerrit with go-gerrit
Browse files Browse the repository at this point in the history
This brings us in line with our other Gerrit clients in Go:

* services/svc/webhooks/gerritstatusupdater/gerritstatusupdater.go
* unity-private/cmd/unity/cmd/change_resolver.go

Beyond the consistency and ease of maintenance for us,
x/build is tailored for the Go team's needs with build.golang.org,
whereas go-gerrit is a generic client library for everyone else.

The next commit will start using an authenticated Gerrit client,
so it was important to do this first to not write even more code
against x/build when we wanted to switch away from it.

Verified that runtrybot still works via https://cuelang.org/cl/553879.

Fixes #22.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: Ib8017b642307b028b7873cd127ff083d5260b8d6
Dispatch-Trailer: {"type":"trybot","CL":557233,"patchset":4,"ref":"refs/changes/33/557233/4","targetBranch":"master"}
  • Loading branch information
mvdan authored and cueckoo committed Aug 3, 2023
1 parent eadcfcc commit 8ce2a7e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions cmd/cueckoo/cmd/cltrigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"sync"

"golang.org/x/build/gerrit"
"github.com/andygrunwald/go-gerrit"
)

var (
Expand Down Expand Up @@ -243,8 +243,8 @@ func (c *cltrigger) triggerBuilds(revs []revision) error {
}

func (c *cltrigger) triggerBuild(rev revision) error {
in, err := c.cfg.gerritClient.GetChange(context.Background(), rev.changeID, gerrit.QueryChangesOpt{
Fields: []string{"ALL_REVISIONS"},
in, _, err := c.cfg.gerritClient.Changes.GetChange(rev.changeID, &gerrit.ChangeOptions{
AdditionalFields: []string{"ALL_REVISIONS"},
})
if err != nil {
// Note that this may be a "change not found" error when the changeID is
Expand All @@ -263,8 +263,8 @@ func (c *cltrigger) triggerBuild(rev revision) error {
}

return c.builder(repositoryDispatchPayload{
CL: in.ChangeNumber,
Patchset: revision.PatchSetNumber,
CL: in.Number,
Patchset: revision.Number,
TargetBranch: in.Branch,
Ref: revision.Ref,
})
Expand Down
7 changes: 5 additions & 2 deletions cmd/cueckoo/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"os"
"strings"

"github.com/andygrunwald/go-gerrit"
"github.com/cue-sh/tools/internal/codereviewcfg"
"github.com/google/go-github/v53/github"
"golang.org/x/build/gerrit"
)

// eventType values define an enumeration of the various
Expand Down Expand Up @@ -129,7 +129,10 @@ func loadConfig(ctx context.Context) (*config, error) {
return nil, err
}
res.githubClient = github.NewClient(auth.Client())
res.gerritClient = gerrit.NewClient(res.gerritURL, gerrit.NoAuth)
res.gerritClient, err = gerrit.NewClient(res.gerritURL, nil)
if err != nil {
return nil, err
}

return &res, nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/cue-sh/tools
go 1.20

require (
github.com/andygrunwald/go-gerrit v0.0.0-20230628115649-c44fe2fbf2ca
github.com/google/go-cmp v0.5.9
github.com/google/go-github/v53 v53.2.0
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466
github.com/spf13/cobra v1.7.0
golang.org/x/build v0.0.0-20230803004431-0ffd0a3c2eeb
golang.org/x/oauth2 v0.10.0
golang.org/x/sync v0.3.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/andygrunwald/go-gerrit v0.0.0-20230628115649-c44fe2fbf2ca h1:q9HI3vudtbNNvaZl+l0oM7cQ07OES2x7ysiVwZpk89E=
github.com/andygrunwald/go-gerrit v0.0.0-20230628115649-c44fe2fbf2ca/go.mod h1:SeP12EkHZxEVjuJ2HZET304NBtHGG2X6w2Gzd0QXAZw=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
Expand All @@ -26,8 +28,6 @@ github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRM
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/build v0.0.0-20230803004431-0ffd0a3c2eeb h1:OZVITzrlw1c7/06dovaxuU7ENj0Yvcnp9MaFL4KBksU=
golang.org/x/build v0.0.0-20230803004431-0ffd0a3c2eeb/go.mod h1:BSNTRjnkSrSRPGSoC0mMk4FQJ++jXO0zkfroNK5pyMU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
Expand Down

0 comments on commit 8ce2a7e

Please sign in to comment.