👔 Enhance hostname normalization#125
Merged
Merged
Conversation
To support both - GitHub Enterprise Server (GHES) and - GitHub Enterprise Cloud with Data Residency (GHEC+DR)
Enhance hostname handling and normalization details
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances GitHub API hostname handling to properly support GitHub Enterprise Cloud with Data Residency (GHEC+DR) regional domains while preserving existing behavior for GitHub Enterprise Server (GHES) instances.
- Adds logic to detect
*.ghe.comdomains and prefix them withapi.instead of appending/api/v3 - Introduces a
getBaseUrl()helper function for introspecting resolved API base URLs - Replaces placeholder tests with concrete assertions using dynamic imports to isolate module state
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/github/octokit.js | Enhanced hostname normalization logic and added getBaseUrl helper |
| test/github/octokit.test.js | Replaced placeholder tests with concrete hostname normalization tests |
| readme.md | Added comprehensive hostname handling documentation table |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
This PR enhances GitHub API hostname handling to properly support GitHub Enterprise Cloud with Data Residency (GHEC+DR) regional domains while preserving existing behavior for GitHub Enterprise Server (GHES) instances. It also adds a helper to improve test reliability and strengthens hostname-related test coverage.
🔍 Changes
src/github/octokit.jshostname normalization:region.ghe.com→https://api.region.ghe.comapi.region.ghe.comstayshttps://api.region.ghe.com(no/api/v3appended)ghe.internal.example.com) →https://<host>/api/v3https://api.github.comgetBaseUrl(octokit)to safely introspect the resolved API base URL.test/github/octokit.test.jsby:baseUrlvalues instead of placeholder checks.api.-prefixed regional hosts.🤔 Rationale
Previously, any provided hostname was coerced into the GHES pattern with
/api/v3. GHEC+DR regional endpoints (*.ghe.com) instead use anapi.subdomain (e.g.api.region1.ghe.com) without/api/v3. The old logic produced incorrect URLs for these environments, breaking API calls. This update corrects that and avoids double-prefixing when the user already supplies anapi.host.🛠 Implementation Details
Logic branch in
octokit.js:*.ghe.comvia regex.api.-prefixed, addapi..api.-prefixed domains./api/v3only to non-public, non-*.ghe.comcustom hosts.https://api.github.comwhen no hostname is provided.getBaseUrl()helper (additive, non-breaking) for introspection/testing.✅ Testing
Updated
octokit.test.js:jest.resetModules()to isolate singleton state.client.request.endpoint.DEFAULTS.baseUrlfor all hostname variants.api.-prefixed regional hosts.Result: 216 tests passing, coverage ~87% statements / ~88% branches.
🔄 Backward Compatibility
getOctokitunchanged.*.ghe.comnow resolves correctly; alreadyapi.prefixed hosts no longer risk unintended/api/v3suffixes.📈 Impact / Risk
Low risk: Narrow conditional change, fully covered by targeted tests.
📝 Checklist