feat: add WithBaseURL option for custom API base URLs (#50)#51
Merged
Conversation
Add WithBaseURL, an InstallationTokenSourceOpt that sets the GitHub API base URL verbatim (only normalizing a trailing slash), closely mirroring how go-github lets callers target a custom endpoint. Unlike WithEnterpriseURL it does not append "/api/v3/", which unblocks: - GitHub Enterprise Cloud with data residency (https://api.SUBDOMAIN.ghe.com/) - pointing the client at an httptest server in tests Also harden the installation-token options so they cannot be misconfigured: - Option order no longer matters. WithHTTPClient previously rebuilt the client and silently discarded any base URL or retry setting applied before it; it now swaps only the underlying *http.Client. - Invalid base URLs and a nil HTTP client are reported by the first Token() call instead of silently falling back to the public GitHub API. And apply a few idiomatic, non-breaking cleanups: - WithHTTPClient operates on a shallow copy so the caller's *http.Client is no longer mutated. - Drop the deprecated, no-op net.Dialer.DualStack field. - Rename the unexported githubClient.client field to httpClient. README documents WithBaseURL vs WithEnterpriseURL; tests cover the new option, order-independence, fail-loud misconfiguration, and that the caller's HTTP client is not mutated.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #51 +/- ##
==========================================
+ Coverage 93.81% 94.15% +0.34%
==========================================
Files 4 4
Lines 307 325 +18
==========================================
+ Hits 288 306 +18
Misses 12 12
Partials 7 7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Description
Add WithBaseURL, an InstallationTokenSourceOpt that sets the GitHub API base URL verbatim (only normalizing a trailing slash), closely mirroring how go-github lets callers target a custom endpoint. Unlike WithEnterpriseURL it does not append "/api/v3/", which unblocks:
Also harden the installation-token options so they cannot be misconfigured:
And apply a few idiomatic, non-breaking cleanups:
README documents WithBaseURL vs WithEnterpriseURL; tests cover the new option, order-independence, fail-loud misconfiguration, and that the caller's HTTP client is not mutated.
Related Issues
#50