Skip to content

Fix add-wizard/add --create-pull-request failing on GitHub Enterprise Server repos#20898

Merged
pelikhan merged 3 commits intomainfrom
copilot/fix-ghes-pr-creation-error
Mar 14, 2026
Merged

Fix add-wizard/add --create-pull-request failing on GitHub Enterprise Server repos#20898
pelikhan merged 3 commits intomainfrom
copilot/fix-ghes-pr-creation-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 14, 2026

gh pr create --repo owner/repo without --hostname always routes to github.com, so PR creation fails with a repository-not-found GraphQL error when the git remote points to a GHES instance.

Changes

  • pkg/cli/git.go: Added extractHostFromRemoteURL(url) — parses the hostname from any git remote URL format (HTTPS, HTTP, SSH scp-like git@host:path, SSH URL ssh://[user@]host/path), defaulting to github.com on failure. Added getHostFromOriginRemote() — reads remote.origin.url via git config and returns its hostname.

  • pkg/cli/pr_command.go: createPR() now calls getHostFromOriginRemote() and appends --hostname <host> to both the gh repo view and gh pr create invocations when the remote host is not github.com.

  • pkg/cli/git_test.go: Table-driven tests for extractHostFromRemoteURL (HTTPS, SSH, SSH URL, port, edge cases) and integration tests for getHostFromOriginRemote against a real temp git repo.

# Before: always hit github.com → "Could not resolve to a Repository"
gh aw add-wizard githubnext/agentics/ci-doctor --create-pull-request

# After: --hostname ghes.example.com derived from origin remote → PR created on GHES

Copilot AI and others added 2 commits March 14, 2026 01:49
When adding a workflow with --create-pull-request in a repo whose origin
points to GitHub Enterprise Server, detect the host from the git remote
URL and pass --hostname to gh pr create, so the PR is created on the
correct GHES instance instead of always defaulting to github.com.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
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

Fixes add-wizard / add --create-pull-request PR creation against GitHub Enterprise Server by deriving the host from remote.origin.url and passing it through to gh invocations.

Changes:

  • Add git-remote host extraction helpers (extractHostFromRemoteURL, getHostFromOriginRemote).
  • Update PR creation flow to add --hostname <host> to gh repo view and gh pr create when the origin remote is not github.com.
  • Add unit tests for URL parsing and an integration-style test that reads remote.origin.url from a temp git repo.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/cli/git.go Adds helpers to derive host from remote.origin.url.
pkg/cli/pr_command.go Uses derived host to route gh commands to GHES via --hostname.
pkg/cli/git_test.go Adds tests for host parsing and origin-remote host detection.
.changeset/patch-fix-ghes-pr-creation.md Documents the fix as a patch changeset.

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

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@pelikhan pelikhan merged commit 5dc8091 into main Mar 14, 2026
52 checks passed
@pelikhan pelikhan deleted the copilot/fix-ghes-pr-creation-error branch March 14, 2026 02:53
github-actions bot added a commit that referenced this pull request Mar 14, 2026
… configuration

Expand the GitHub Enterprise Server Support section in the CLI reference
to cover two improvements merged on 2026-03-14:

- Commands with --create-pull-request (add, add-wizard, init, update, upgrade)
  now automatically detect the enterprise host from the git remote and route
  PR creation to the correct GHES instance (from #20898)

- The bundled configure_gh_for_ghe.sh helper script is now available at
  /opt/gh-aw/actions/ for workflows that use custom steps with gh CLI on GHES.
  Includes a usage example and note about automatic GITHUB_SERVER_URL detection
  (from #20878)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add-wizard and add --create-pull-request fail to create PR on GitHub Enterprise Server repositories

3 participants