Skip to content

Commit

Permalink
Merge pull request #5 from hellofresh/patch/http-timeouts
Browse files Browse the repository at this point in the history
adding timeout to github client
  • Loading branch information
loginakhil authored Apr 27, 2020
2 parents 7543bda + f1eaeb8 commit add6885
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http"
"time"

"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -61,13 +62,19 @@ func NewGithubClient(
token string,
releaseFilter ReleaseFilter,
assetFilter AssetFilter,
connectionTimeout time.Duration,
) *GithubLocator {
var httpClient *http.Client
if token != "" {
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
httpClient = oauth2.NewClient(context.Background(), src)
httpClient.Timeout = connectionTimeout
}

if httpClient == nil {
httpClient = &http.Client{Timeout: connectionTimeout}
}

client := githubv4.NewClient(httpClient)
Expand Down

0 comments on commit add6885

Please sign in to comment.