Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix NewWithTokenWithClient so it preserves the original http client t… #338

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions github/github.go
Original file line number Diff line number Diff line change
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