Skip to content

👔 Enhance hostname normalization#125

Merged
stoe merged 3 commits into
mainfrom
stoe/ghecdr
Oct 3, 2025
Merged

👔 Enhance hostname normalization#125
stoe merged 3 commits into
mainfrom
stoe/ghecdr

Conversation

@stoe
Copy link
Copy Markdown
Owner

@stoe stoe commented Oct 2, 2025

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

  • Updated src/github/octokit.js hostname normalization:
    • region.ghe.comhttps://api.region.ghe.com
    • api.region.ghe.com stays https://api.region.ghe.com (no /api/v3 appended)
    • Any other custom host (e.g. ghe.internal.example.com) → https://<host>/api/v3
    • No hostname → https://api.github.com
  • Added named export getBaseUrl(octokit) to safely introspect the resolved API base URL.
  • Strengthened test/github/octokit.test.js by:
    • Resetting module state per test via dynamic imports.
    • Asserting actual baseUrl values instead of placeholder checks.
    • Adding explicit tests for default, GHES, GHEC+DR, and already api.-prefixed regional hosts.
  • Ensured overall suite remains green (216 tests passing) with slight coverage improvement for branch logic.

🤔 Rationale

Previously, any provided hostname was coerced into the GHES pattern with /api/v3. GHEC+DR regional endpoints (*.ghe.com) instead use an api. 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 an api. host.

🛠 Implementation Details

Logic branch in octokit.js:

  • Detect *.ghe.com via regex.
  • If not already api.-prefixed, add api..
  • Preserve already api.-prefixed domains.
  • Apply /api/v3 only to non-public, non-*.ghe.com custom hosts.
  • Fallback to https://api.github.com when no hostname is provided.
  • Exported getBaseUrl() helper (additive, non-breaking) for introspection/testing.

✅ Testing

Updated octokit.test.js:

  • Dynamic import after jest.resetModules() to isolate singleton state.
  • Assertions on client.request.endpoint.DEFAULTS.baseUrl for all hostname variants.
  • Added test for preserving already api.-prefixed regional hosts.

Result: 216 tests passing, coverage ~87% statements / ~88% branches.

🔄 Backward Compatibility

  • Public API for getOctokit unchanged.
  • Existing GHES behavior intact.
  • Only difference: *.ghe.com now resolves correctly; already api. prefixed hosts no longer risk unintended /api/v3 suffixes.
  • Added export is purely additive.

📈 Impact / Risk

Low risk: Narrow conditional change, fully covered by targeted tests.

📝 Checklist

  • Code changes implemented
  • Tests updated / added
  • All tests passing locally
  • No breaking changes
  • README hostname section (pending / optional)

To support both
- GitHub Enterprise Server (GHES) and
- GitHub Enterprise Cloud with Data Residency (GHEC+DR)
@stoe stoe self-assigned this Oct 2, 2025
stoe added 2 commits October 2, 2025 09:03
Enhance hostname handling and normalization details
@stoe stoe added the feature-request 🚧 Want something new? label Oct 3, 2025
@stoe stoe marked this pull request as ready for review October 3, 2025 14:08
Copilot AI review requested due to automatic review settings October 3, 2025 14:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.com domains and prefix them with api. 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.

@stoe stoe merged commit 4b3552c into main Oct 3, 2025
8 checks passed
@stoe stoe deleted the stoe/ghecdr branch October 3, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-request 🚧 Want something new?

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants