Skip to content

Commit a24df16

Browse files
authored
Merge pull request #174 from chrisgavin/add-retries
Add a retrying HTTP client.
2 parents 9f14698 + f16603b commit a24df16

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/cli/safeexec v1.0.1
99
github.com/go-git/go-git/v5 v5.12.0
1010
github.com/golangci/golangci-lint v1.61.0
11+
github.com/hashicorp/go-retryablehttp v0.7.7
1112
github.com/pkg/errors v0.9.1
1213
github.com/sirupsen/logrus v1.9.3
1314
github.com/spf13/cobra v1.8.1
@@ -96,6 +97,7 @@ require (
9697
github.com/gostaticanalysis/comment v1.4.2 // indirect
9798
github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect
9899
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
100+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
99101
github.com/hashicorp/go-version v1.7.0 // indirect
100102
github.com/hashicorp/hcl v1.0.0 // indirect
101103
github.com/henvic/httpretty v0.0.6 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ github.com/gostaticanalysis/testutil v0.4.0 h1:nhdCmubdmDF6VEatUNjgUZBJKWRqugoIS
334334
github.com/gostaticanalysis/testutil v0.4.0/go.mod h1:bLIoPefWXrRi/ssLFWX1dx7Repi5x3CuviD3dgAZaBU=
335335
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
336336
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
337+
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
338+
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
339+
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
340+
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
341+
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
342+
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
337343
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
338344
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
339345
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=

internal/client/client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ package client
33
import (
44
"github.com/cli/go-gh"
55
"github.com/cli/go-gh/pkg/api"
6+
"github.com/hashicorp/go-retryablehttp"
67
"github.com/pkg/errors"
78
)
89

910
func NewClient(host string) (api.RESTClient, error) {
10-
client, err := gh.RESTClient(&api.ClientOptions{Host: host})
11+
retryableHTTPClient := retryablehttp.NewClient()
12+
retryableHTTPClient.RetryMax = 5
13+
retryableRoundTripper := retryablehttp.RoundTripper{Client: retryableHTTPClient}
14+
15+
client, err := gh.RESTClient(&api.ClientOptions{Host: host, Transport: &retryableRoundTripper})
1116
if err != nil {
1217
return nil, errors.Wrap(err, "Unable to create GitHub client.")
1318
}

0 commit comments

Comments
 (0)