Skip to content

fix: only call gh for GitHub hosts - #93

Merged
him0 merged 1 commit into
mainfrom
fix/gh-host-check
Nov 20, 2026
Merged

him0 merged 1 commit into
mainfrom
fix/gh-host-check

Conversation

@him0

@him0 him0 commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Problem

For a gone branch whose commits are not in the default branch, gh-sync runs gh api graphql --hostname <host>, with the host taken from the remote URL. The remote can be any git server, and gh applies GH_ENTERPRISE_TOKEN / GITHUB_ENTERPRISE_TOKEN to every host other than github.com. So with that variable set, running gh sync in a repository whose remote is not on GitHub sent the token to https://<host>/api/graphql.

Fix

checkGhHost runs before gh api and only lets through:

  • github.com, its subdomains and *.ghe.com
  • the host named by GH_HOST
  • a host with credentials stored by gh auth login, checked with gh auth token --hostname <host> run without the token environment variables (the printed token is discarded)

Any other host is a failed lookup, as before for an unauthenticated gh: a warning, and the branches that depend on the lookup are kept. The answer is cached per host for the sync.

Behavior change

A GitHub Enterprise Server host used only through GH_ENTERPRISE_TOKEN, with neither gh auth login nor GH_HOST, no longer gets squash-merge detection. Setting GH_HOST restores it. Both READMEs say so.

Testing

  • mise run test and mise run lint pass.
  • New unit tests cover the host classification, the environment filtering and the rejection of an unknown host with GH_ENTERPRISE_TOKEN set.
  • Checked by hand with the built binary, a fake gh that records its calls and GH_ENTERPRISE_TOKEN set: no gh api call for an unknown host; gh api is called with GH_HOST set or when gh auth token succeeds. The stored-credentials path with a real gh login is not covered by an automated test.

🤖 Generated with Claude Code

The host passed to `gh api graphql --hostname` comes from the remote URL,
which can be any git server. gh sends GH_ENTERPRISE_TOKEN (and
GITHUB_ENTERPRISE_TOKEN) to every host other than github.com, so a sync in
a repository whose remote is not on GitHub sent that token to the remote's
host.

gh is now only called for github.com, *.ghe.com, the host in GH_HOST and
hosts with credentials stored by `gh auth login`. Any other host is a
failed lookup: the branches that depend on it are kept.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@him0
him0 merged commit 03e2162 into main Nov 20, 2026
6 of 7 checks passed
@him0
him0 deleted the fix/gh-host-check branch November 20, 2026 19:00
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.

1 participant