Skip to content

Commit

Permalink
Merge pull request #338 from rawlingsj/fix_new_token_with_client
Browse files Browse the repository at this point in the history
fix NewWithTokenWithClient so it preserves the original http client t…
  • Loading branch information
k8s-ci-robot committed Apr 11, 2024
2 parents 7eaf28a + b0673ea commit 1590f5a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions github/github.go
Expand Up @@ -226,14 +226,20 @@ func NewWithToken(token string) (*GitHub, error) {
// Empty string will result in unauthenticated client, which makes
// unauthenticated requests.
func NewWithTokenWithClient(token string, httpClient *http.Client) (*GitHub, error) {
ctx := context.Background()
client := httpClient
state := unauthenticated
if token != "" {
state = strings.TrimPrefix(state, "un")
client = oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))
// Set the Transport of the existing httpClient to include the OAuth2 transport
if client == nil {
client = &http.Client{}
}
client.Transport = &oauth2.Transport{
Source: oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
),
Base: client.Transport, // Preserve the original transport
}
}

logrus.Debugf("Using %s GitHub client", state)
Expand Down

0 comments on commit 1590f5a

Please sign in to comment.