Fix GitHub Enterprise host identity loss across PR/work-item paths

- Thread `host` through mobile PR RPC params, IPC work-item lookups, and
  RPC schemas so GHES identity survives the renderer/mobile/main boundary
  instead of silently falling back to a same-named github.com repo.
- Qualify `--repo`/`-R` args for github.com too (not just GHES), since
  gh resolves bare shorthand against a process-level GH_HOST that can
  redirect pinned github.com commands.
- Cache `getOriginGitHubApiRepository` to avoid a per-call uncached
  `git remote get-url` round trip on connection-backed repos.
- Add a local-fork fallback in `getWorkItemDetails` so PRs living on a
  base repo (not visible via the origin slug) still resolve via cwd.
- Centralize the github.com-vs-GHES host predicate in
  `isDefaultGitHubHost` so cache keys, quota scoping, and identity
  checks can't drift out of sync.
This commit is contained in:
Jinjing
2026-07-19 18:03:48 -07:00
parent 8ad7686fe3
commit bcb895bf43
28 changed files with 288 additions and 79 deletions
+14 -18
View File
@@ -86,7 +86,6 @@ import {
rememberGhCwdResolutionFailure
} from './gh-cwd-repo-negative-cache'
import type { GitHubRepoContext } from './github-repository-identity'
import { getEnterpriseGitHubRepoSlug } from './github-enterprise-repository'
import {
getOriginGitHubApiRepository,
githubHostExecOptions,
@@ -118,7 +117,6 @@ import {
import { mapGraphQLReactionGroups, type GitHubGraphQLReactionGroup } from './comment-reactions'
import {
getRateLimit,
noteRateLimitSpend,
noteRepositoryRateLimitSpend,
rateLimitGuard,
repositoryRateLimitGuard,
@@ -1516,7 +1514,7 @@ async function countWorkItemsForQuery(
)
// Why: over-counts gh cache hits, which is the safe direction — the search
// bucket is only 30/min and the next probe corrects the estimate.
noteRateLimitSpend('search')
noteRepositoryRateLimitSpend(ownerRepo, 'search', 1, localGitOptions)
return Number.parseInt(stdout.trim(), 10) || 0
}
@@ -1576,8 +1574,11 @@ export async function countWorkItems(
// 30/min, so a multi-repo Tasks page must stop counting when the budget is
// gone instead of converting the remaining repos into 403 spawns. getRateLimit
// is 30s-cached and single-flight, so priming here is one spawn per window.
await getRateLimit()
if (rateLimitGuard('search').blocked) {
// Only shared github.com traffic consults the snapshot; other scopes bypass.
if (spendsSharedGitHubComQuota(ownerRepo, localGitOptions)) {
await getRateLimit()
}
if (repositoryRateLimitGuard(ownerRepo, 'search', localGitOptions).blocked) {
return 0
}
@@ -1882,18 +1883,13 @@ export async function createGitHubPullRequest(
}
}
// Why: github.com-only slug parsing returns null for GHES, so fall back to the
// enterprise resolver (gh-authenticated custom host) before giving up (#8312).
// Creation targets origin: the head branch is unqualified, so `gh pr create`
// must run against the repo the branch was pushed to, not the fork parent
// (getOwnerRepo became upstream-first for PR reads in #7331).
const ownerRepo =
(await getOwnerRepoForRemote(
repoPath,
'origin',
connectionId,
...hostedReviewLocalGitOptionArgs(options)
)) ?? (await getEnterpriseGitHubRepoSlug(repoPath, connectionId, options))
// Why: creation targets the origin that owns the unqualified head branch;
// the shared resolver also preserves its execution host (#7331, #8312).
const ownerRepo = await getOriginGitHubApiRepository(
repoPath,
connectionId,
getHostedReviewLocalGitOptions(options)
)
if (!ownerRepo) {
return {
ok: false,
@@ -4371,7 +4367,7 @@ export async function getPRComments(
['pr', 'view', String(prNumber), '--json', 'comments'],
ghOptions
)
noteRateLimitSpend('graphql')
noteRepositoryRateLimitSpend(ownerRepo, 'graphql', 1, ghOptions)
const data = JSON.parse(stdout) as {
comments: {
author: { login: string }