From 8201e8c874af20bb0989f55d929f6cf3c276c193 Mon Sep 17 00:00:00 2001 From: Akhil Thayyil Date: Mon, 27 Apr 2020 11:44:03 +0200 Subject: [PATCH 1/2] adding timeout to github client --- github.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/github.go b/github.go index 74f2eac..3e79b56 100644 --- a/github.go +++ b/github.go @@ -4,6 +4,7 @@ import ( "context" "errors" "net/http" + "time" "github.com/shurcooL/githubv4" "golang.org/x/oauth2" @@ -61,6 +62,7 @@ func NewGithubClient( token string, releaseFilter ReleaseFilter, assetFilter AssetFilter, + connectionTimeout time.Duration, ) *GithubLocator { var httpClient *http.Client if token != "" { @@ -70,6 +72,12 @@ func NewGithubClient( httpClient = oauth2.NewClient(context.Background(), src) } + if httpClient == nil { + httpClient = http.DefaultClient + } + + httpClient.Timeout = connectionTimeout + client := githubv4.NewClient(httpClient) return &GithubLocator{ client: client, From f1eaeb811e5aa5dc9dece147294a979813943864 Mon Sep 17 00:00:00 2001 From: Akhil Thayyil Date: Mon, 27 Apr 2020 14:26:32 +0200 Subject: [PATCH 2/2] CR Fixes --- github.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/github.go b/github.go index 3e79b56..85c2775 100644 --- a/github.go +++ b/github.go @@ -70,14 +70,13 @@ func NewGithubClient( &oauth2.Token{AccessToken: token}, ) httpClient = oauth2.NewClient(context.Background(), src) + httpClient.Timeout = connectionTimeout } if httpClient == nil { - httpClient = http.DefaultClient + httpClient = &http.Client{Timeout: connectionTimeout} } - httpClient.Timeout = connectionTimeout - client := githubv4.NewClient(httpClient) return &GithubLocator{ client: client,