@@ -11,7 +11,7 @@ import (
11
11
"strings"
12
12
"sync"
13
13
14
- "github.com/google/go-github/v48 /github"
14
+ "github.com/google/go-github/v58 /github"
15
15
"github.com/gotgenes/getignore/pkg/getignore"
16
16
)
17
17
@@ -20,24 +20,26 @@ var DefaultMaxRequests = runtime.NumCPU() - 1
20
20
21
21
// Getter lists and gets files using the GitHub tree API.
22
22
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
30
31
}
31
32
32
33
// getterParams holds parameters for instantiating a Getter
33
34
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
41
43
}
42
44
43
45
func NewGetter (options ... GetterOption ) (Getter , error ) {
@@ -55,13 +57,12 @@ func NewGetter(options ...GetterOption) (Getter, error) {
55
57
ghClient * github.Client
56
58
err error
57
59
)
60
+ ghClient = github .NewClient (params .client )
58
61
if params .baseURL != "" {
59
- ghClient , err = github . NewEnterpriseClient (params .baseURL , params .baseURL , params . client )
62
+ ghClient , err = ghClient . WithEnterpriseURLs (params .baseURL , params .baseURL )
60
63
if err != nil {
61
64
return Getter {}, err
62
65
}
63
- } else {
64
- ghClient = github .NewClient (params .client )
65
66
}
66
67
userAgentString := fmt .Sprintf (userAgentTemplate , getignore .Version )
67
68
ghClient .UserAgent = userAgentString
@@ -127,6 +128,13 @@ func WithMaxRequests(max int) GetterOption {
127
128
}
128
129
}
129
130
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
+
130
138
// List returns an array of files filtered by the provided suffix.
131
139
func (g Getter ) List (ctx context.Context ) ([]string , error ) {
132
140
tree , err := g .getTree (ctx )
@@ -229,7 +237,7 @@ func (g Getter) newGetError(err error) error {
229
237
}
230
238
231
239
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 )
233
241
if err != nil {
234
242
return nil , errors .New ("unable to get branch information" )
235
243
}
0 commit comments