Skip to content

feat: add WithBaseURL option for custom API base URLs (#50)#51

Merged
jferrl merged 1 commit into
mainfrom
feat/with-base-url
Jun 30, 2026
Merged

feat: add WithBaseURL option for custom API base URLs (#50)#51
jferrl merged 1 commit into
mainfrom
feat/with-base-url

Conversation

@jferrl

@jferrl jferrl commented Jun 30, 2026

Copy link
Copy Markdown
Owner

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:

  • 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.

Related Issues

#50

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

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.15%. Comparing base (aea57f2) to head (b96f2a2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jferrl
jferrl merged commit 3d8cba2 into main Jun 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants