Skip to content

fix: correct GHES URL wiring and Docker client build args - #2

Merged
mbianchidev merged 4 commits into
mainfrom
copilot/fix-ghes-graphql-endpoint
May 29, 2026
Merged

fix: correct GHES URL wiring and Docker client build args#2
mbianchidev merged 4 commits into
mainfrom
copilot/fix-ghes-graphql-endpoint

Conversation

Copilot AI commented May 29, 2026

Copy link
Copy Markdown

Pull Request

Proposed Changes

This updates the GHE.com / GHES support work to close the remaining gaps in endpoint resolution and client build-time configuration. The main fixes are correct GHES GraphQL routing, Docker forwarding of NEXT_PUBLIC_* values, protocol-safe auth URLs, and integration coverage for the affected wiring.

  • GraphQL endpoint resolution

    • Add getGitHubGraphQlUrl() to derive the correct endpoint for:
      • github.comhttps://api.github.com/graphql
      • *.ghe.comhttps://api.<tenant>.ghe.com/graphql
      • GHES → https://<host>/api/graphql
    • Wire Octokit/Probot GraphQL clients to use the derived GraphQL URL instead of relying on REST baseUrl inference for GHES.
  • Client build-time GitHub host configuration

    • Update the Dockerfile builder stage to accept and export:
      • NEXT_PUBLIC_GITHUB_SERVER_URL
      • NEXT_PUBLIC_GITHUB_API_URL
    • Align README / development docs with the actual Docker behavior instead of telling users to patch the Dockerfile manually.
  • Auth and server-side URL consistency

    • Update generateAuthUrl() to preserve the configured GitHub server protocol and host instead of hardcoding https://.
    • Add a server-only one-time warning when a non-github.com server is configured but GITHUB_USER_EMAIL_DOMAIN is not set.
  • Shared derivation rules / drift reduction

    • Document the webhook relay fallback derivation so its REST URL rules stay aligned with src/utils/github-urls.ts.
  • Focused integration coverage

    • Add/extend tests for:
      • URL helper derivation, including GHES GraphQL behavior and explicit overrides
      • Octokit REST/GraphQL wiring
      • NextAuth userinfo.request email fallback using the configured API host
      • generateAuthUrl() host/protocol handling
      • committer email warning behavior
      • Dockerfile + docs consistency for NEXT_PUBLIC_* build args

Example of the GHES-specific behavior this change locks in:

getGitHubApiUrl()      // https://ghes.example.com/api/v3
getGitHubGraphQlUrl()  // https://ghes.example.com/api/graphql

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • run npm run format and fix any formatting issues that have been introduced
  • run npm run lint and fix any linting issues that have been introduced
  • run npm run test and run tests

Copilot AI changed the title [WIP] Fix GraphQL endpoint for GHES support fix: correct GHES URL wiring and Docker client build args May 29, 2026
Copilot AI requested a review from mbianchidev May 29, 2026 09:44
@mbianchidev
mbianchidev marked this pull request as ready for review May 29, 2026 13:30
@mbianchidev
mbianchidev requested a review from Copilot May 29, 2026 13:30

Copilot AI left a comment

Copy link
Copy Markdown

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 closes remaining gaps in GHE.com / GHES support: it adds proper GraphQL endpoint derivation, ensures the Octokit GraphQL client (including Probot's) targets the right host, makes generateAuthUrl() honor the configured protocol, forwards NEXT_PUBLIC_* build args through the Dockerfile, and adds a server-side warning when GITHUB_USER_EMAIL_DOMAIN is left unset on non-github.com deployments. Documentation and focused integration tests are added/updated accordingly.

Changes:

  • Introduce getGitHubGraphQlUrl() / getGitHubServerProtocol() and wire them into Octokit, Probot, and authenticated git remotes.
  • Extract createGitHubUserinfoRequest and add getCommitterEmailDomainWithWarning (one-shot warning) for non-github.com hosts.
  • Forward NEXT_PUBLIC_GITHUB_SERVER_URL / NEXT_PUBLIC_GITHUB_API_URL as Docker build args, update README/docs/.env.example, and add integration tests covering all of the above.
Show a summary per file
File Description
src/utils/github-urls.ts Adds getGitHubGraphQlUrl, getGitHubServerProtocol, and a shared isGithubDotComHost helper.
src/utils/auth.ts generateAuthUrl now preserves the configured server protocol.
src/utils/server/committer-email.ts New helper logging a one-time warning when default email domain is used on non-github.com servers.
src/bot/rest.ts Adds githubGraphQlEndpointPlugin and registers it on the shared Octokit.
src/bot/octokit.ts (context) generateAppAccessToken already uses derived REST baseUrl.
src/pages/api/webhooks.ts Applies the GraphQL endpoint plugin to Probot's Octokit.
src/app/api/auth/lib/nextauth-options.ts Extracts createGitHubUserinfoRequest to use the configured API host.
src/server/git/controller.ts, src/server/repos/controller.ts Switch to getCommitterEmailDomainWithWarning.
scripts/webhook-relay.mjs Adds a sync-with-github-urls comment for the local REST URL derivation.
Dockerfile Accepts and exports NEXT_PUBLIC_GITHUB_SERVER_URL / NEXT_PUBLIC_GITHUB_API_URL before npm run build.
README.md, docs/developing.md, .env.example Document the Dockerfile already forwards the build args and the new warning behavior.
test/github-urls.test.ts New GraphQL/protocol assertions, including explicit GHES /api/v3 override.
test/bot/octokit.test.ts Verifies REST + GraphQL endpoints for GHES and GHE.com, plus app auth baseUrl.
test/app/api/auth/nextauth-options.test.ts Covers email fallback against the configured API host.
test/utils/auth.test.ts Covers protocol/host handling in generateAuthUrl.
test/utils/server/committer-email.test.ts Verifies one-time warning and explicit-domain behavior.
test/docs/docker-build-config.test.ts Ensures Dockerfile and docs stay in sync about build args.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 19/19 changed files
  • Comments generated: 0

@mbianchidev

mbianchidev commented May 29, 2026

Copy link
Copy Markdown
Owner

@copilot apply these non-critical changes from review

The path aliasing for the mocked 'utils/pem' module should work if Vitest is configured with the same TypeScript path aliases, and since the author claims the tests pass, I'll assume that's handled correctly.

I notice isGithubDotComServer in committer-email.ts duplicates logic that already exists as isGithubDotComHost in github-urls.ts—a minor redundancy but not critical. Overall the review looks solid with no major issues to flag.

Copilot AI commented May 29, 2026

Copy link
Copy Markdown
Author

@copilot apply these non-critical changes from review

The path aliasing for the mocked 'utils/pem' module should work if Vitest is configured with the same TypeScript path aliases, ...

Fixed the isGithubDotComServer redundancy — exported isGithubDotComHost from github-urls.ts and reused it in committer-email.ts instead of duplicating the logic. All 97 tests pass.

@mbianchidev
mbianchidev merged commit 1537836 into main May 29, 2026
@mbianchidev
mbianchidev deleted the copilot/fix-ghes-graphql-endpoint branch July 28, 2026 13:33
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.

3 participants