Skip to content

Commit 9036fe2

Browse files
committedJan 25, 2024
Upgrade go-github.
1 parent 0dcc036 commit 9036fe2

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed
 

‎cmd/getignore/common.go

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ var commonFlags = []cli.Flag{
3535
Usage: "The suffix to use to identify ignore files",
3636
Value: github.Suffix,
3737
},
38+
&cli.IntFlag{
39+
Name: "max-redirects",
40+
Usage: "The maximum number of redirects to follow",
41+
Value: github.MaxRedirects,
42+
},
3843
}
3944

4045
var stringFlagsToOptions = map[string]func(string) github.GetterOption{

‎go.mod

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/gotgenes/getignore
33
go 1.21
44

55
require (
6-
github.com/google/go-github/v48 v48.1.0
6+
github.com/google/go-github/v58 v58.0.0
77
github.com/onsi/ginkgo/v2 v2.15.0
88
github.com/onsi/gomega v1.31.1
99
github.com/urfave/cli/v2 v2.27.1
@@ -19,7 +19,6 @@ require (
1919
github.com/google/pprof v0.0.0-20240125082051-42cd04596328 // indirect
2020
github.com/russross/blackfriday/v2 v2.1.0 // indirect
2121
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e // indirect
22-
golang.org/x/crypto v0.18.0 // indirect
2322
golang.org/x/net v0.20.0 // indirect
2423
golang.org/x/sys v0.16.0 // indirect
2524
golang.org/x/text v0.14.0 // indirect

‎go.sum

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
1414
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1515
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1616
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
17-
github.com/google/go-github/v48 v48.1.0 h1:nqPqq+0oRY2AMR/SRskGrrP4nnewPB7e/m2+kbT/UvM=
18-
github.com/google/go-github/v48 v48.1.0/go.mod h1:dDlehKBDo850ZPvCTK0sEqTCVWcrGl2LcDiajkYi89Y=
17+
github.com/google/go-github/v58 v58.0.0 h1:Una7GGERlF/37XfkPwpzYJe0Vp4dt2k1kCjlxwjIvzw=
18+
github.com/google/go-github/v58 v58.0.0/go.mod h1:k4hxDKEfoWpSqFlc8LTpGd9fu2KrV1YAa6Hi6FmDNY4=
1919
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
2020
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
2121
github.com/google/pprof v0.0.0-20240125082051-42cd04596328 h1:oI+lCI2DY1BsRrdzMJBhIMxBBdlZJl31YNQC11EiyvA=
@@ -35,8 +35,6 @@ github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
3535
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
3636
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI=
3737
github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
38-
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
39-
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
4038
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
4139
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
4240
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=

‎pkg/github/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ const (
77
Suffix = ".gitignore"
88

99
userAgentTemplate = "getignore/%s"
10+
MaxRedirects = 3
1011
)

‎pkg/github/getter.go

+27-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"strings"
1212
"sync"
1313

14-
"github.com/google/go-github/v48/github"
14+
"github.com/google/go-github/v58/github"
1515
"github.com/gotgenes/getignore/pkg/getignore"
1616
)
1717

@@ -20,24 +20,26 @@ var DefaultMaxRequests = runtime.NumCPU() - 1
2020

2121
// Getter lists and gets files using the GitHub tree API.
2222
type Getter struct {
23-
client *github.Client
24-
BaseURL string
25-
Owner string
26-
Repository string
27-
Branch string
28-
Suffix string
29-
MaxRequests int
23+
client *github.Client
24+
BaseURL string
25+
Owner string
26+
Repository string
27+
Branch string
28+
Suffix string
29+
MaxRequests int
30+
MaxRedirects int
3031
}
3132

3233
// getterParams holds parameters for instantiating a Getter
3334
type getterParams struct {
34-
client *http.Client
35-
baseURL string
36-
owner string
37-
repository string
38-
branch string
39-
suffix string
40-
maxRequests int
35+
client *http.Client
36+
baseURL string
37+
owner string
38+
repository string
39+
branch string
40+
suffix string
41+
maxRequests int
42+
maxRedirects int
4143
}
4244

4345
func NewGetter(options ...GetterOption) (Getter, error) {
@@ -55,13 +57,12 @@ func NewGetter(options ...GetterOption) (Getter, error) {
5557
ghClient *github.Client
5658
err error
5759
)
60+
ghClient = github.NewClient(params.client)
5861
if params.baseURL != "" {
59-
ghClient, err = github.NewEnterpriseClient(params.baseURL, params.baseURL, params.client)
62+
ghClient, err = ghClient.WithEnterpriseURLs(params.baseURL, params.baseURL)
6063
if err != nil {
6164
return Getter{}, err
6265
}
63-
} else {
64-
ghClient = github.NewClient(params.client)
6566
}
6667
userAgentString := fmt.Sprintf(userAgentTemplate, getignore.Version)
6768
ghClient.UserAgent = userAgentString
@@ -127,6 +128,13 @@ func WithMaxRequests(max int) GetterOption {
127128
}
128129
}
129130

131+
// WithMaxRedirects sets the number of maximum redirects to follow
132+
func WithMaxRedirects(max int) GetterOption {
133+
return func(p *getterParams) {
134+
p.maxRedirects = max
135+
}
136+
}
137+
130138
// List returns an array of files filtered by the provided suffix.
131139
func (g Getter) List(ctx context.Context) ([]string, error) {
132140
tree, err := g.getTree(ctx)
@@ -229,7 +237,7 @@ func (g Getter) newGetError(err error) error {
229237
}
230238

231239
func (g Getter) getTree(ctx context.Context) (*github.Tree, error) {
232-
branch, _, err := g.client.Repositories.GetBranch(ctx, g.Owner, g.Repository, g.Branch, true)
240+
branch, _, err := g.client.Repositories.GetBranch(ctx, g.Owner, g.Repository, g.Branch, g.MaxRedirects)
233241
if err != nil {
234242
return nil, errors.New("unable to get branch information")
235243
}

0 commit comments

Comments
 (0)
Please sign in to comment.