Deduplicate OAuth2 provider HTTP client fallback#328
Merged
Conversation
5 tasks
Copilot
AI
changed the title
[WIP] Fix duplicate httpClient helper method in OAuth2 providers
Deduplicate OAuth2 provider HTTP client fallback
May 23, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR deduplicates the nil -> http.DefaultClient fallback logic for OAuth2 provider HTTP clients by introducing a shared helper in the provider implementation file, keeping built-in provider request paths consistent and easier to maintain.
Changes:
- Added a package-level
resolveHTTPClient(*http.Client) *http.Clienthelper to centralize defaulting behavior. - Removed duplicated per-provider
httpClient()methods fromGitHubProviderandGoogleOAuth2Provider, updating request execution to use the shared helper. - Added a unit test to cover both the “provided client” and “nil fallback” cases.
Show a summary per file
| File | Description |
|---|---|
| handler/oauth2_providers.go | Centralizes HTTP client fallback logic and updates built-in providers to use it. |
| handler/oauth2_providers_test.go | Adds targeted unit test coverage for the shared HTTP client resolution helper. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both built-in OAuth2 providers carried the same
HTTPClientnil-fallback logic, creating unnecessary duplication in a shared request path. This change consolidates that behavior so future client customization stays in one place.Shared HTTP client resolution
resolveHTTPClienthelper inhandler/oauth2_providers.gonil -> http.DefaultClientfallback used by built-in OAuth2 providersProvider cleanup
httpClient()methods from:GitHubProviderGoogleOAuth2ProviderFocused coverage
http.DefaultClientwhen absentGreptile Summary
This PR removes duplicated
httpClient()methods fromGitHubProviderandGoogleOAuth2Providerby extracting their shared nil-fallback logic into a single package-levelresolveHTTPClienthelper.resolveHTTPClient(*http.Client) *http.Clientinhandler/oauth2_providers.go, replacing two identical receiver methods with a single shared implementation.handler/oauth2_providers_test.go) covering both the injected-client andhttp.DefaultClientfallback paths.Confidence Score: 5/5
Safe to merge — this is a pure refactor with no behavior change.
The extracted resolveHTTPClient helper is logically identical to the two methods it replaces, all three call sites are updated consistently, and the new tests confirm both branches. There is no changed behavior, no new dependency, and no untested path.
No files require special attention.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["Provider method\n(fetchGitHubUser /\nfetchGitHubPrimaryEmail /\nFetchUserInfo)"] --> B["resolveHTTPClient(p.HTTPClient)"] B --> C{client != nil?} C -- Yes --> D["Return injected *http.Client"] C -- No --> E["Return http.DefaultClient"] D --> F["client.Do(req)"] E --> FReviews (1): Last reviewed commit: "refactor: share oauth2 provider HTTP cli..." | Re-trigger Greptile