Route gh host qualification through runner options instead of argv sniff

Move GHES/GH_HOST resolution from parsing --hostname/--repo out of gh argv to an explicit options.host passed through ghExecFileAsync, since SSH-backed repos spawn gh with no cwd and argv sniffing couldn't reliably detect the target host. The runner now injects --hostname and qualifies --repo/-R at spawn time from options.host, and rate-limit scoping/guards use the same explicit host instead of inferring it. Also adds a shared githubRepoIdentityKey helper to keep cache/store keys consistent with the new host-aware repository identity.
This commit is contained in:
Jinjing
2026-07-19 18:03:48 -07:00
parent 273c56c54f
commit 58034d2f74
28 changed files with 590 additions and 327 deletions
+10 -8
View File
@@ -167,7 +167,7 @@ describe('createGitHubPullRequest', () => {
expect(args[args.indexOf('--head') + 1]).toBe('my-branch')
})
it('host-qualifies --repo for a GHES remote so gh targets the Enterprise server (#8312)', async () => {
it('routes --repo to the Enterprise server via options.host for a GHES remote (#8312)', async () => {
// github.com-only slug parsing misses GHES, so creation comes from the
// enterprise resolver, which carries the host.
getOwnerRepoMock.mockResolvedValueOnce(null)
@@ -194,13 +194,14 @@ describe('createGitHubPullRequest', () => {
url: 'https://github.acme-corp.com/team/orca/pull/7'
})
const [args] = ghExecFileAsyncMock.mock.calls[0]
// Bare "team/orca" would resolve against gh's default host (github.com);
// the host prefix pins the command to the Enterprise server.
expect(args[args.indexOf('--repo') + 1]).toBe('github.acme-corp.com/team/orca')
const [args, options] = ghExecFileAsyncMock.mock.calls[0]
// The runner host-qualifies argv at spawn time from options.host, so the
// mocked call sees a bare owner/repo plus the host in exec options.
expect(args[args.indexOf('--repo') + 1]).toBe('team/orca')
expect(options).toMatchObject({ host: 'github.acme-corp.com' })
})
it('host-qualifies --repo for the GHES existing-PR fallback lookup (#8312)', async () => {
it('routes the GHES existing-PR fallback lookup through options.host (#8312)', async () => {
getOwnerRepoMock.mockResolvedValue(null)
getEnterpriseGitHubRepoSlugMock.mockResolvedValue({
owner: 'team',
@@ -234,9 +235,10 @@ describe('createGitHubPullRequest', () => {
existingReview: { number: 9, url: 'https://github.acme-corp.com/team/orca/pull/9' }
})
const [listArgs] = ghExecFileAsyncMock.mock.calls[1]
const [listArgs, listOptions] = ghExecFileAsyncMock.mock.calls[1]
expect(listArgs).toEqual(expect.arrayContaining(['pr', 'list']))
expect(listArgs[listArgs.indexOf('--repo') + 1]).toBe('github.acme-corp.com/team/orca')
expect(listArgs[listArgs.indexOf('--repo') + 1]).toBe('team/orca')
expect(listOptions).toMatchObject({ host: 'github.acme-corp.com' })
})
it('runs local WSL project pull request creation through the selected distro', async () => {
+6 -8
View File
@@ -134,15 +134,13 @@ describe('setPRFileViewed', () => {
})
).resolves.toBe(true)
// The runner injects --hostname at spawn time from options.host, so the
// mocked call sees unqualified argv plus the Enterprise host in options.
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
expect.arrayContaining([
'api',
'--hostname',
'github.acme-corp.com',
'graphql',
'pullRequestId=PR_enterprise'
]),
{}
expect.arrayContaining(['api', 'graphql', 'pullRequestId=PR_enterprise']),
{ host: 'github.acme-corp.com' }
)
const [args] = ghExecFileAsyncMock.mock.calls[0]
expect(args).not.toContain('--hostname')
})
})
+4 -1
View File
@@ -44,7 +44,10 @@ vi.mock('./gh-utils', async () => {
vi.mock('./rate-limit', () => ({
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: noteRateLimitSpendMock,
getRateLimit: vi.fn(async () => ({ ok: false, error: 'not probed in tests' }))
getRateLimit: vi.fn(async () => ({ ok: false, error: 'not probed in tests' })),
repositoryRateLimitGuard: vi.fn(() => ({ blocked: false })),
noteRepositoryRateLimitSpend: vi.fn(),
spendsSharedGitHubComQuota: () => true
}))
import { countWorkItems, getWorkItem, listWorkItems, _resetOwnerRepoCache } from './client'
@@ -28,7 +28,10 @@ vi.mock('../git/runner', () => ({
vi.mock('./rate-limit', () => ({
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: vi.fn()
noteRateLimitSpend: vi.fn(),
repositoryRateLimitGuard: vi.fn(() => ({ blocked: false })),
noteRepositoryRateLimitSpend: vi.fn(),
spendsSharedGitHubComQuota: vi.fn(() => true)
}))
import { getPRCheckDetails, _resetOwnerRepoCache } from './client'
@@ -212,9 +215,9 @@ describe('getPRCheckDetails', () => {
})
it('isolates failed-job log tails for the same job ID on different GitHub hosts', async () => {
ghExecFileAsyncMock.mockImplementation(async (args: string[]) => {
ghExecFileAsyncMock.mockImplementation(async (args: string[], options?: { host?: string }) => {
const endpoint = args.find((arg) => arg.startsWith('repos/')) ?? ''
const enterprise = args.includes('github.acme-corp.com')
const enterprise = options?.host === 'github.acme-corp.com'
if (endpoint.endsWith('/check-runs/99')) {
return {
stdout: JSON.stringify({
@@ -264,6 +267,6 @@ describe('getPRCheckDetails', () => {
args.some((arg) => arg.endsWith('/actions/jobs/9901/logs'))
)
expect(logCalls).toHaveLength(2)
expect(logCalls[1]?.[0]).toEqual(expect.arrayContaining(['--hostname', 'github.acme-corp.com']))
expect(logCalls[1]?.[1]).toEqual(expect.objectContaining({ host: 'github.acme-corp.com' }))
})
})
+10 -1
View File
@@ -10,6 +10,9 @@ const {
getRateLimitMock,
rateLimitGuardMock,
noteRateLimitSpendMock,
repositoryRateLimitGuardMock,
noteRepositoryRateLimitSpendMock,
spendsSharedGitHubComQuotaMock,
acquireMock,
releaseMock
} = vi.hoisted(() => ({
@@ -31,6 +34,9 @@ const {
getRateLimitMock: vi.fn(),
rateLimitGuardMock: vi.fn(() => ({ blocked: false })),
noteRateLimitSpendMock: vi.fn(),
repositoryRateLimitGuardMock: vi.fn(() => ({ blocked: false })),
noteRepositoryRateLimitSpendMock: vi.fn(),
spendsSharedGitHubComQuotaMock: vi.fn(() => true),
acquireMock: vi.fn(),
releaseMock: vi.fn()
}))
@@ -66,7 +72,10 @@ vi.mock('../git/runner', () => ({
vi.mock('./rate-limit', () => ({
getRateLimit: getRateLimitMock,
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: noteRateLimitSpendMock
noteRateLimitSpend: noteRateLimitSpendMock,
repositoryRateLimitGuard: repositoryRateLimitGuardMock,
noteRepositoryRateLimitSpend: noteRepositoryRateLimitSpendMock,
spendsSharedGitHubComQuota: spendsSharedGitHubComQuotaMock
}))
import { getPRChecks, rerunPRChecks, _resetOwnerRepoCache } from './client'
+16 -10
View File
@@ -93,7 +93,15 @@ vi.mock('./conflict-summary', () => ({
vi.mock('./rate-limit', () => ({
getRateLimit: getRateLimitMock,
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: noteRateLimitSpendMock
noteRateLimitSpend: noteRateLimitSpendMock,
repositoryRateLimitGuard: vi.fn(() => ({ blocked: false })),
noteRepositoryRateLimitSpend: vi.fn(),
spendsSharedGitHubComQuota: (
repository?: { host?: string } | null,
executionOptions?: { wslDistro?: string }
) =>
(!repository?.host || repository.host.toLowerCase() === 'github.com') &&
!executionOptions?.wslDistro
}))
import {
@@ -488,16 +496,14 @@ describe('GitHub PR local runtime routing', () => {
const prViewCall = ghExecFileAsyncMock.mock.calls.find(
([args]) => args[0] === 'pr' && args[1] === 'view'
)
expect(prViewCall?.[0]).toEqual(
expect.arrayContaining(['--repo', 'github.acme-corp.com/team/orca'])
)
expect(prViewCall?.[1]).toEqual({})
// The runner host-qualifies argv at spawn time from options.host, so the
// mocked call sees the unqualified --repo plus the host in exec options.
expect(prViewCall?.[0]).toEqual(expect.arrayContaining(['--repo', 'team/orca']))
expect(prViewCall?.[1]).toEqual({ host: 'github.acme-corp.com' })
const prCalls = ghExecFileAsyncMock.mock.calls.filter(([args]) => args[0] === 'pr')
expect(
prCalls.every(
([args]) =>
args.includes('--repo') &&
args[args.indexOf('--repo') + 1] === 'github.acme-corp.com/team/orca'
([args]) => args.includes('--repo') && args[args.indexOf('--repo') + 1] === 'team/orca'
)
).toBe(true)
const apiCalls = ghExecFileAsyncMock.mock.calls.filter(([args]) => args[0] === 'api')
@@ -505,8 +511,8 @@ describe('GitHub PR local runtime routing', () => {
expect(
apiCalls.every(
([args, options]) =>
args.includes('--hostname') &&
args[args.indexOf('--hostname') + 1] === 'github.acme-corp.com' &&
!args.includes('--hostname') &&
options.host === 'github.acme-corp.com' &&
options.cwd === undefined &&
options.wslDistro === undefined
)
+4 -1
View File
@@ -64,7 +64,10 @@ vi.mock('../git/runner', () => ({
vi.mock('./rate-limit', () => ({
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: noteRateLimitSpendMock,
getRateLimit: vi.fn(async () => ({ ok: false, error: 'not probed in tests' }))
getRateLimit: vi.fn(async () => ({ ok: false, error: 'not probed in tests' })),
repositoryRateLimitGuard: vi.fn(() => ({ blocked: false })),
noteRepositoryRateLimitSpend: vi.fn(),
spendsSharedGitHubComQuota: () => true
}))
import {
+11 -6
View File
@@ -101,7 +101,14 @@ vi.mock('./local-git-config-signature', () => ({
vi.mock('./rate-limit', () => ({
getRateLimit: getRateLimitMock,
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: noteRateLimitSpendMock
noteRateLimitSpend: noteRateLimitSpendMock,
// Why: the repository-scoped guards share the same bucket-keyed budget as the
// legacy ones, so delegate to the existing mocks to keep per-bucket blocking
// and spend assertions working unchanged.
repositoryRateLimitGuard: (_repository: unknown, bucket: string) => rateLimitGuardMock(bucket),
noteRepositoryRateLimitSpend: (_repository: unknown, bucket: string) =>
noteRateLimitSpendMock(bucket),
spendsSharedGitHubComQuota: () => true
}))
import {
@@ -4189,9 +4196,9 @@ describe('GitHub GraphQL rate-limit guard', () => {
baseRefName: 'main',
headRefOid: 'head-oid'
}
ghExecFileAsyncMock.mockImplementation(async (args) => {
ghExecFileAsyncMock.mockImplementation(async (args, options) => {
if (args.includes('graphql')) {
const enterprise = args.includes('github.acme-corp.com')
const enterprise = options?.host === 'github.acme-corp.com'
return {
stdout: JSON.stringify({
data: {
@@ -4223,9 +4230,7 @@ describe('GitHub GraphQL rate-limit guard', () => {
expect(enterprise?.autoMergeAllowed).toBe(false)
const graphqlCalls = ghExecFileAsyncMock.mock.calls.filter(([args]) => args.includes('graphql'))
expect(graphqlCalls).toHaveLength(2)
expect(graphqlCalls[1]?.[0]).toEqual(
expect.arrayContaining(['--hostname', 'github.acme-corp.com'])
)
expect(graphqlCalls[1]?.[1]).toEqual(expect.objectContaining({ host: 'github.acme-corp.com' }))
})
it('returns conflicting file details instead of running gh merge when PR is dirty', async () => {
+114 -145
View File
@@ -89,13 +89,12 @@ import type { GitHubRepoContext } from './github-repository-identity'
import { getEnterpriseGitHubRepoSlug } from './github-enterprise-repository'
import {
getOriginGitHubApiRepository,
githubApiHostArgs,
githubCliRepositoryArgument,
githubHostExecOptions,
githubRepositoryWebHost,
isGitHubDotComRepository,
resolveGitHubApiRepository,
type GitHubApiRepository
} from './github-api-repository'
import { githubRepoIdentityKey } from '../../shared/github-repository-identity-key'
export { _resetOwnerRepoCache } from './gh-utils'
export {
getIssue,
@@ -120,11 +119,14 @@ import { mapGraphQLReactionGroups, type GitHubGraphQLReactionGroup } from './com
import {
getRateLimit,
noteRateLimitSpend,
noteRepositoryRateLimitSpend,
rateLimitGuard,
repositoryRateLimitGuard,
spendsSharedGitHubComQuota,
type RateLimitBucketKind
} from './rate-limit'
type GhExecOptions = ReturnType<typeof ghRepoExecOptions>
type GhExecOptions = ReturnType<typeof ghRepoExecOptions> & { host?: string }
type HostedReviewLocalGitOptions = ReturnType<typeof getHostedReviewLocalGitOptions>
const ORCA_REPO = 'stablyai/orca'
@@ -191,9 +193,7 @@ async function assertRateLimitBudget(
repository?: GitHubApiRepository | null,
executionOptions?: Pick<GhExecOptions, 'wslDistro'>
): Promise<void> {
// The global snapshot is for the default github.com account. Applying it to
// GHES or WSL can block a healthy runtime based on an unrelated quota.
if ((repository && !isGitHubDotComRepository(repository)) || executionOptions?.wslDistro) {
if (!spendsSharedGitHubComQuota(repository, executionOptions)) {
return
}
await getRateLimit()
@@ -205,27 +205,6 @@ async function assertRateLimitBudget(
}
}
function noteRepositoryRateLimitSpend(
repository: GitHubApiRepository | null,
bucket: RateLimitBucketKind,
cost = 1,
executionOptions?: Pick<GhExecOptions, 'wslDistro'>
): void {
if ((!repository || isGitHubDotComRepository(repository)) && !executionOptions?.wslDistro) {
noteRateLimitSpend(bucket, cost)
}
}
function repositoryRateLimitGuard(
repository: GitHubApiRepository | null,
bucket: RateLimitBucketKind,
executionOptions?: Pick<GhExecOptions, 'wslDistro'>
): ReturnType<typeof rateLimitGuard> {
return (!repository || isGitHubDotComRepository(repository)) && !executionOptions?.wslDistro
? rateLimitGuard(bucket)
: { blocked: false }
}
function prRefreshUpstreamError(
err: unknown
): Extract<PRRefreshOutcome, { kind: 'upstream-error' }> {
@@ -862,14 +841,13 @@ async function fetchIssueWorkItem(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<MainWorkItem | null> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
if (ownerRepo) {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues/${number}`
],
['api', `repos/${ownerRepo.owner}/${ownerRepo.repo}/issues/${number}`],
ghOptions
)
const item = JSON.parse(stdout) as Record<string, unknown>
@@ -903,7 +881,7 @@ async function fetchPullRequestReviewFields(
'view',
String(number),
'--repo',
githubCliRepositoryArgument(ownerRepo),
`${ownerRepo.owner}/${ownerRepo.repo}`,
'--json',
WORK_ITEM_PR_REVIEW_JSON_FIELDS
]
@@ -930,7 +908,10 @@ async function fetchPullRequestWorkItem(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<MainWorkItem> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
if (ownerRepo) {
try {
const { stdout } = await ghExecFileAsync(
@@ -939,7 +920,7 @@ async function fetchPullRequestWorkItem(
'view',
String(number),
'--repo',
githubCliRepositoryArgument(ownerRepo),
`${ownerRepo.owner}/${ownerRepo.repo}`,
'--json',
WORK_ITEM_PR_DETAIL_JSON_FIELDS
],
@@ -968,11 +949,7 @@ async function fetchPullRequestWorkItem(
}
} catch {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${number}`
],
['api', `repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${number}`],
ghOptions
)
const mapped = mapPullRequestWorkItem(
@@ -1819,7 +1796,7 @@ function parseCreatePRPayload(stdout: string): { number: number; url: string } |
async function findOpenPRByHeadBase(args: {
repoPath: string
repoArg: string
repo: GitHubApiRepository
head: string
base: string
connectionId?: string | null
@@ -1831,7 +1808,7 @@ async function findOpenPRByHeadBase(args: {
'pr',
'list',
'--repo',
args.repoArg,
`${args.repo.owner}/${args.repo.repo}`,
'--head',
args.head,
'--base',
@@ -1845,7 +1822,8 @@ async function findOpenPRByHeadBase(args: {
],
{
...ghRepoExecOptions(context),
...(args.connectionId ? {} : getHostedReviewLocalGitOptions(args.options))
...(args.connectionId ? {} : getHostedReviewLocalGitOptions(args.options)),
...githubHostExecOptions(args.repo)
}
)
const list = JSON.parse(stdout) as { number?: number; url?: string }[]
@@ -1923,8 +1901,8 @@ export async function createGitHubPullRequest(
error: 'Creating pull requests requires a GitHub remote.'
}
}
// Host-qualified for GHES so gh targets the Enterprise server, not github.com.
const repoArg = githubCliRepositoryArgument(ownerRepo)
// The runner host-qualifies --repo from options.host for GHES (#8312).
const repoArg = `${ownerRepo.owner}/${ownerRepo.repo}`
const base = normalizeHostedReviewBaseRef(input.base)
const head = input.head ? normalizeHostedReviewHeadRef(input.head) || undefined : undefined
@@ -1976,6 +1954,7 @@ export async function createGitHubPullRequest(
const { stdout } = await ghExecFileAsync(createArgs, {
...ghRepoExecOptions(context),
...(connectionId ? {} : getHostedReviewLocalGitOptions(options)),
...githubHostExecOptions(ownerRepo),
timeout: 60_000,
idempotent: false
})
@@ -1986,7 +1965,7 @@ export async function createGitHubPullRequest(
const found = head
? await findOpenPRByHeadBase({
repoPath,
repoArg,
repo: ownerRepo,
head,
base,
connectionId,
@@ -2010,7 +1989,7 @@ export async function createGitHubPullRequest(
) {
const existing = await findOpenPRByHeadBase({
repoPath,
repoArg,
repo: ownerRepo,
head,
base,
connectionId,
@@ -2287,8 +2266,7 @@ async function detectRepositoryMergeMetadata(
branchName: string | undefined,
ghOptions: GhExecOptions
): Promise<GitHubRepositoryMergeMetadata> {
const host = ownerRepo.host?.toLowerCase() ?? 'github.com'
const cacheKey = `${host}/${ownerRepo.owner.toLowerCase()}/${ownerRepo.repo.toLowerCase()}:${branchName ?? '__repo__'}`
const cacheKey = `${githubRepoIdentityKey(ownerRepo)}:${branchName ?? '__repo__'}`
pruneRepositoryMergeMetadataCache()
const cached = repositoryMergeMetadataCache.get(cacheKey)
if (cached) {
@@ -2322,7 +2300,6 @@ async function detectRepositoryMergeMetadata(
noteRepositoryRateLimitSpend(ownerRepo, 'graphql', 1, ghOptions)
const args = [
'api',
...githubApiHostArgs(ownerRepo),
'graphql',
'-f',
`query=${query}`,
@@ -2334,7 +2311,10 @@ async function detectRepositoryMergeMetadata(
if (branchName) {
args.push('-f', `branch=${branchName}`)
}
const { stdout } = await ghExecFileAsync(args, ghOptions)
const { stdout } = await ghExecFileAsync(args, {
...ghOptions,
...githubHostExecOptions(ownerRepo)
})
const parsed = JSON.parse(stdout) as {
data?: {
repository?: {
@@ -2420,12 +2400,8 @@ async function getRestPRForBranch(
): Promise<PullRequestLookupData | null> {
const head = encodeURIComponent(`${headOwner}:${branchName}`)
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(prRepo),
`repos/${prRepo.owner}/${prRepo.repo}/pulls?head=${head}&state=all&per_page=1`
],
ghOptions
['api', `repos/${prRepo.owner}/${prRepo.repo}/pulls?head=${head}&state=all&per_page=1`],
{ ...ghOptions, ...githubHostExecOptions(prRepo) }
)
const list = JSON.parse(stdout) as RestPullRequest[]
const pr = list[0]
@@ -2442,7 +2418,7 @@ async function getFallbackPRListForBranch(
'pr',
'list',
'--repo',
githubCliRepositoryArgument(prRepo),
`${prRepo.owner}/${prRepo.repo}`,
'--head',
branchName,
'--state',
@@ -2452,7 +2428,7 @@ async function getFallbackPRListForBranch(
'--json',
PR_BRANCH_LIST_JSON_FIELDS
],
ghOptions
{ ...ghOptions, ...githubHostExecOptions(prRepo) }
)
const list = JSON.parse(stdout) as PullRequestLookupData[]
return list[0] ?? null
@@ -2855,12 +2831,8 @@ async function getRestPRByNumber(
ghOptions: ReturnType<typeof ghRepoExecOptions>
): Promise<PullRequestLookupData | null> {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${number}`
],
ghOptions
['api', `repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${number}`],
{ ...ghOptions, ...githubHostExecOptions(ownerRepo) }
)
return mapRestPullRequest(JSON.parse(stdout) as RestPullRequest)
}
@@ -2877,11 +2849,11 @@ async function getPRByNumber(
'view',
String(number),
'--repo',
githubCliRepositoryArgument(ownerRepo),
`${ownerRepo.owner}/${ownerRepo.repo}`,
'--json',
PR_LOOKUP_JSON_FIELDS
],
ghOptions
{ ...ghOptions, ...githubHostExecOptions(ownerRepo) }
)
return hydratePullRequestLookupData(
ownerRepo,
@@ -3566,7 +3538,6 @@ async function getPRChecksViaRestFallback(
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
...cacheArgs,
`repos/${ownerRepo.owner}/${ownerRepo.repo}/commits/${encodedHeadSha}/check-runs?per_page=100`
],
@@ -3584,7 +3555,6 @@ async function getPRChecksViaRestFallback(
const statusResult = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
...cacheArgs,
`repos/${ownerRepo.owner}/${ownerRepo.repo}/commits/${encodedHeadSha}/status?per_page=100`
],
@@ -3608,7 +3578,6 @@ async function getPRChecksViaRestFallback(
const suitesResult = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
...cacheArgs,
`repos/${ownerRepo.owner}/${ownerRepo.repo}/commits/${encodedHeadSha}/check-suites?per_page=100`
],
@@ -3655,13 +3624,16 @@ export async function getPRChecks(
localGitOptions: LocalGitExecOptions = {}
): Promise<PRCheckDetail[]> {
void headSha
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
prRepo,
connectionId,
localGitOptions
)
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
if (connectionId && !ownerRepo) {
throw new Error(GITHUB_WORK_ITEMS_SSH_REMOTE_REQUIRED_MESSAGE)
}
@@ -3671,7 +3643,7 @@ export async function getPRChecks(
try {
const fallbackArgs = ['pr', 'checks', String(prNumber), '--json', 'name,state,link']
if (ownerRepo) {
fallbackArgs.push('--repo', githubCliRepositoryArgument(ownerRepo))
fallbackArgs.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
const { stdout } = await ghExecFileAsync(fallbackArgs, ghOptions).catch((err: unknown) => {
const { stderr } = extractExecError(err)
@@ -3713,7 +3685,6 @@ export async function getPRChecks(
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'graphql',
...cacheArgs,
'-f',
@@ -3889,9 +3860,7 @@ async function attachFailedJobLogTails(
// a lazy, bounded follow-up request instead of a burst of hosted log downloads.
for (const job of failedJobs) {
const jobCacheKey = getCheckJobLogTailCacheKey(job)
const cacheKey = jobCacheKey
? `${githubRepositoryWebHost(ownerRepo).toLowerCase()}/${ownerRepo.owner.toLowerCase()}/${ownerRepo.repo.toLowerCase()}:${jobCacheKey}`
: null
const cacheKey = jobCacheKey ? `${githubRepoIdentityKey(ownerRepo)}:${jobCacheKey}` : null
if (!cacheKey) {
continue
}
@@ -3901,11 +3870,7 @@ async function attachFailedJobLogTails(
}
try {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
`repos/${ownerRepo.owner}/${ownerRepo.repo}/actions/jobs/${job.id}/logs`
],
['api', `repos/${ownerRepo.owner}/${ownerRepo.repo}/actions/jobs/${job.id}/logs`],
ghOptions
)
job.logTail = sliceCheckLogTail(stdout)
@@ -3944,7 +3909,6 @@ export async function getPRCheckDetails(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<PRCheckRunDetails | null> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
args.prRepo,
@@ -3954,6 +3918,10 @@ export async function getPRCheckDetails(
if (!ownerRepo) {
return null
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
@@ -3961,11 +3929,7 @@ export async function getPRCheckDetails(
let annotations: PRCheckRunDetails['annotations'] = []
if (args.checkRunId) {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
`repos/${ownerRepo.owner}/${ownerRepo.repo}/check-runs/${args.checkRunId}`
],
['api', `repos/${ownerRepo.owner}/${ownerRepo.repo}/check-runs/${args.checkRunId}`],
ghOptions
)
checkRun = JSON.parse(stdout) as Record<string, unknown>
@@ -3973,7 +3937,6 @@ export async function getPRCheckDetails(
const annotationsResult = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
`repos/${ownerRepo.owner}/${ownerRepo.repo}/check-runs/${args.checkRunId}/annotations?per_page=20`
],
ghOptions
@@ -3991,7 +3954,6 @@ export async function getPRCheckDetails(
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
`repos/${ownerRepo.owner}/${ownerRepo.repo}/actions/runs/${workflowRunId}/jobs?per_page=100`
],
ghOptions
@@ -4048,11 +4010,14 @@ export async function rerunPRChecks(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<GitHubRerunPRChecksResult> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await getOriginGitHubApiRepository(repoPath, connectionId, localGitOptions)
if (!ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
const checks = await getPRChecks(
repoPath,
@@ -4096,7 +4061,7 @@ export async function rerunPRChecks(
const endpoint = options.failedOnly
? `repos/${ownerRepo.owner}/${ownerRepo.repo}/actions/runs/${runId}/rerun-failed-jobs`
: `repos/${ownerRepo.owner}/${ownerRepo.repo}/actions/runs/${runId}/rerun`
await ghExecFileAsync(['api', ...githubApiHostArgs(ownerRepo), '-X', 'POST', endpoint], {
await ghExecFileAsync(['api', '-X', 'POST', endpoint], {
...ghOptions,
env: { ...process.env, GH_PROMPT_DISABLED: '1' }
})
@@ -4106,7 +4071,6 @@ export async function rerunPRChecks(
await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'-X',
'POST',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/check-runs/${checkRunId}/rerequest`
@@ -4189,13 +4153,16 @@ export async function getPRComments(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<PRComment[]> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
options?.prRepo,
connectionId,
localGitOptions
)
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
if (connectionId && !ownerRepo) {
throw new Error(GITHUB_WORK_ITEMS_SSH_REMOTE_REQUIRED_MESSAGE)
}
@@ -4223,7 +4190,6 @@ export async function getPRComments(
reviewThreadsFetch = ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'graphql',
'-f',
`query=${REVIEW_THREADS_QUERY}`,
@@ -4239,12 +4205,7 @@ export async function getPRComments(
}
const [issueResult, threadsResult, reviewsResult] = await Promise.allSettled([
ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
...cacheArgs,
`${base}/issues/${prNumber}/comments?per_page=100`
],
['api', ...cacheArgs, `${base}/issues/${prNumber}/comments?per_page=100`],
ghOptions
),
reviewThreadsFetch,
@@ -4253,12 +4214,7 @@ export async function getPRComments(
// Without this, a reviewer who submits "LGTM" without inline threads
// would have their comment silently dropped from the panel.
ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
...cacheArgs,
`${base}/pulls/${prNumber}/reviews?per_page=100`
],
['api', ...cacheArgs, `${base}/pulls/${prNumber}/reviews?per_page=100`],
ghOptions
)
])
@@ -4451,9 +4407,6 @@ export async function setPRFileViewed(args: {
path: string
viewed: boolean
}): Promise<boolean> {
const ghOptions = ghRepoExecOptions(
githubRepoContext(args.repoPath, args.connectionId, args.localGitOptions)
)
const ownerRepo = await getOriginGitHubApiRepository(
args.repoPath,
args.connectionId,
@@ -4462,6 +4415,10 @@ export async function setPRFileViewed(args: {
if (args.connectionId && !ownerRepo) {
return false
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(args.repoPath, args.connectionId, args.localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
const mutation = args.viewed ? 'markFileAsViewed' : 'unmarkFileAsViewed'
const query = `mutation($pullRequestId: ID!, $path: String!) {
${mutation}(input: { pullRequestId: $pullRequestId, path: $path }) {
@@ -4473,7 +4430,6 @@ export async function setPRFileViewed(args: {
await ghExecFileAsync(
[
'api',
...(ownerRepo ? githubApiHostArgs(ownerRepo) : []),
'graphql',
'-f',
`query=${query}`,
@@ -4505,11 +4461,14 @@ export async function resolveReviewThread(
): Promise<boolean> {
const mutation = resolve ? 'resolveReviewThread' : 'unresolveReviewThread'
const query = `mutation($threadId: ID!) { ${mutation}(input: { threadId: $threadId }) { thread { isResolved } } }`
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await getOriginGitHubApiRepository(repoPath, connectionId, localGitOptions)
if (connectionId && !ownerRepo) {
return false
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
const guard = repositoryRateLimitGuard(ownerRepo, 'graphql', ghOptions)
if (guard.blocked) {
console.warn(
@@ -4521,15 +4480,7 @@ export async function resolveReviewThread(
try {
noteRepositoryRateLimitSpend(ownerRepo, 'graphql', 1, ghOptions)
await ghExecFileAsync(
[
'api',
...(ownerRepo ? githubApiHostArgs(ownerRepo) : []),
'graphql',
'-f',
`query=${query}`,
'-f',
`threadId=${threadId}`
],
['api', 'graphql', '-f', `query=${query}`, '-f', `threadId=${threadId}`],
ghOptions
)
return true
@@ -4584,7 +4535,6 @@ export async function addPRReviewCommentReply(
prRepo?: GitHubApiRepository | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<GitHubCommentResult> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
prRepo,
@@ -4594,12 +4544,15 @@ export async function addPRReviewCommentReply(
if (!ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'-X',
'POST',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${prNumber}/comments/${commentId}/replies`,
@@ -4630,9 +4583,6 @@ export async function addPRReviewComment(
localGitOptions?: LocalGitExecOptions
}
): Promise<GitHubCommentResult> {
const ghOptions = ghRepoExecOptions(
githubRepoContext(args.repoPath, args.connectionId, args.localGitOptions)
)
const ownerRepo = await getOriginGitHubApiRepository(
args.repoPath,
args.connectionId,
@@ -4641,11 +4591,14 @@ export async function addPRReviewComment(
if (!ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(args.repoPath, args.connectionId, args.localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
const fields = [
'api',
...githubApiHostArgs(ownerRepo),
'-X',
'POST',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${args.prNumber}/comments`,
@@ -4699,7 +4652,6 @@ export async function mergePR(
prRepo?: GitHubApiRepository | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<{ ok: true } | { ok: false; error: string }> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
prRepo,
@@ -4709,6 +4661,10 @@ export async function mergePR(
if (connectionId && !ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
const mergeBlocker = await getPRMergeBlocker(
@@ -4728,7 +4684,7 @@ export async function mergePR(
// is handled by worktree deletion (local) and GitHub's auto-delete setting (remote).
const args = ['pr', 'merge', String(prNumber), `--${method}`]
if (ownerRepo) {
args.push('--repo', githubCliRepositoryArgument(ownerRepo))
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
await ghExecFileAsync(args, {
...ghOptions,
@@ -4753,7 +4709,6 @@ export async function setPRAutoMerge(
prRepo?: GitHubApiRepository | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<{ ok: true } | { ok: false; error: string }> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
prRepo,
@@ -4763,6 +4718,10 @@ export async function setPRAutoMerge(
if (connectionId && !ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
if (enabled) {
@@ -4770,7 +4729,7 @@ export async function setPRAutoMerge(
}
const args = ['pr', 'merge', String(prNumber), '--disable-auto']
if (ownerRepo) {
args.push('--repo', githubCliRepositoryArgument(ownerRepo))
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
await ghExecFileAsync(args, {
...ghOptions,
@@ -4809,7 +4768,7 @@ async function getPRAutoMergeIdentity(
): Promise<PRAutoMergeIdentity | null> {
const args = ['pr', 'view', String(prNumber), '--json', PR_AUTO_MERGE_IDENTITY_JSON_FIELDS]
if (ownerRepo) {
args.push('--repo', githubCliRepositoryArgument(ownerRepo))
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
const { stdout } = await ghExecFileAsync(args, ghOptions)
const data = JSON.parse(stdout) as PRAutoMergeIdentity
@@ -4828,7 +4787,7 @@ async function runPRAutoMergeCommand(
): Promise<void> {
const args = ['pr', 'merge', String(prNumber), '--auto', `--${method}`]
if (ownerRepo) {
args.push('--repo', githubCliRepositoryArgument(ownerRepo))
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
await ghExecFileAsync(args, {
...ghOptions,
@@ -4873,7 +4832,6 @@ async function enablePRAutoMerge(
}`
const args = [
'api',
...(ownerRepo ? githubApiHostArgs(ownerRepo) : []),
'graphql',
'-f',
`query=${query}`,
@@ -4969,11 +4927,11 @@ export async function updatePRState(
localGitOptions: LocalGitExecOptions = {}
): Promise<{ ok: true } | { ok: false; error: string }> {
const context = githubRepoContext(repoPath, connectionId, localGitOptions)
const ghOptions = ghRepoExecOptions(context)
const ownerRepo = await getOriginGitHubApiRepository(repoPath, connectionId, localGitOptions)
if (!ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = { ...ghRepoExecOptions(context), ...githubHostExecOptions(ownerRepo) }
await acquire()
try {
@@ -4981,7 +4939,7 @@ export async function updatePRState(
// Why: GitHub can reject REST pull state PATCHes for reopen paths with a
// generic 422; gh's PR commands use GitHub's supported reopen flow.
await ghExecFileAsync(
['pr', cmd, String(prNumber), '--repo', githubCliRepositoryArgument(ownerRepo)],
['pr', cmd, String(prNumber), '--repo', `${ownerRepo.owner}/${ownerRepo.repo}`],
{
...ghOptions
}
@@ -5007,16 +4965,19 @@ export async function requestPRReviewers(
if (logins.length === 0) {
return { ok: false, error: 'Enter at least one reviewer' }
}
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await getOriginGitHubApiRepository(repoPath, connectionId, localGitOptions)
if (connectionId && !ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
const args = ['pr', 'edit', String(prNumber), '--add-reviewer', logins.join(',')]
if (ownerRepo) {
args.push('--repo', githubCliRepositoryArgument(ownerRepo))
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
await ghExecFileAsync(args, {
...ghOptions,
@@ -5043,16 +5004,19 @@ export async function removePRReviewers(
if (logins.length === 0) {
return { ok: false, error: 'Enter at least one reviewer' }
}
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await getOriginGitHubApiRepository(repoPath, connectionId, localGitOptions)
if (connectionId && !ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
const args = ['pr', 'edit', String(prNumber), '--remove-reviewer', logins.join(',')]
if (ownerRepo) {
args.push('--repo', githubCliRepositoryArgument(ownerRepo))
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
await ghExecFileAsync(args, {
...ghOptions,
@@ -5079,7 +5043,6 @@ export async function updatePRTitle(
prRepo?: GitHubApiRepository | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<boolean> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
prRepo,
@@ -5089,11 +5052,15 @@ export async function updatePRTitle(
if (connectionId && !ownerRepo) {
return false
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
await acquire()
try {
const args = ['pr', 'edit', String(prNumber), '--title', title]
if (ownerRepo) {
args.push('--repo', githubCliRepositoryArgument(ownerRepo))
args.push('--repo', `${ownerRepo.owner}/${ownerRepo.repo}`)
}
await ghExecFileAsync(args, {
...ghOptions
@@ -5115,7 +5082,6 @@ export async function updatePRDetails(
prRepo?: GitHubApiRepository | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<{ ok: true } | { ok: false; error: string }> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ownerRepo = await resolveGitHubApiRepository(
repoPath,
prRepo,
@@ -5125,6 +5091,10 @@ export async function updatePRDetails(
if (!ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
const fields: string[] = []
if (updates.title !== undefined) {
@@ -5146,7 +5116,6 @@ export async function updatePRDetails(
await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'-X',
'PATCH',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${prNumber}`,
+8 -11
View File
@@ -45,21 +45,18 @@ export async function resolveGitHubApiRepository(
return connectionId ? null : repository
}
export function githubApiHostArgs(repository: GitHubApiRepository): string[] {
const host = repository.host
return host && host.toLowerCase() !== 'github.com' ? ['--hostname', host] : []
}
export function isGitHubDotComRepository(repository: GitHubApiRepository): boolean {
return !repository.host || repository.host.toLowerCase() === 'github.com'
}
// Why: owner/repo shorthand targets gh's default host, and SSH-backed repos
// have no local cwd from which gh can infer an Enterprise hostname.
export function githubCliRepositoryArgument(repository: GitHubApiRepository): string {
return !isGitHubDotComRepository(repository)
? `${repository.host}/${repository.owner}/${repository.repo}`
: `${repository.owner}/${repository.repo}`
// Why: the gh runner host-qualifies argv (`--hostname`, `HOST/OWNER/REPO`)
// from `options.host`, so merging this into a call's exec options is the one
// step a call site needs to target GHES. github.com stays unset to keep gh's
// default-host resolution (and existing argv) unchanged.
export function githubHostExecOptions(repository: GitHubApiRepository | null | undefined): {
host?: string
} {
return repository?.host && !isGitHubDotComRepository(repository) ? { host: repository.host } : {}
}
export function githubRepositoryWebHost(repository: GitHubApiRepository): string {
@@ -61,10 +61,11 @@ describe('getEnterpriseGitHubRepoSlug', () => {
repo: 'orca',
host: 'github.acme-corp.com'
})
// The auth probe targets the remote's host, not a hardcoded github.com.
// The auth probe targets the remote's host, not a hardcoded github.com, and
// scopes any breaker trip to that host via the exec options.
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['auth', 'status', '--hostname', 'github.acme-corp.com'],
{ cwd: '/repo' }
{ cwd: '/repo', host: 'github.acme-corp.com' }
)
})
@@ -89,7 +90,7 @@ describe('getEnterpriseGitHubRepoSlug', () => {
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['auth', 'status', '--hostname', 'github.acme-corp.com'],
{ cwd: '/repo', wslDistro: 'Ubuntu' }
{ cwd: '/repo', wslDistro: 'Ubuntu', host: 'github.acme-corp.com' }
)
})
@@ -137,7 +138,7 @@ describe('isGitHubHostAuthenticated', () => {
).resolves.toBe(true)
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['auth', 'status', '--hostname', 'github.acme-corp.com'],
{}
{ host: 'github.acme-corp.com' }
)
})
@@ -83,9 +83,12 @@ export async function isGitHubHostAuthenticated(
// Why: provider detection and review loading can probe the same runtime at
// once; coalesce them so one host never spawns duplicate auth subprocesses.
const probe = (async () => {
const execOptions = ghRepoExecOptions(
githubRepoContext(repoPath, connectionId, localGitOptions)
)
const execOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
// Why: scope any rate-limit breaker trip from this probe to the probed
// host, not to gh's default account.
host: normalizedHost
}
let authenticated: boolean
try {
await ghExecFileAsync(['auth', 'status', '--hostname', normalizedHost], execOptions)
+1 -3
View File
@@ -160,15 +160,13 @@ describe('issue source operations', () => {
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
[
'api',
'--hostname',
'github.acme-corp.com',
'-X',
'POST',
'repos/team/orca/issues/7/comments',
'--raw-field',
'body=Enterprise comment'
],
{}
expect.objectContaining({ host: 'github.acme-corp.com' })
)
})
+2 -3
View File
@@ -15,7 +15,7 @@ import type {
} from '../../shared/types'
import { mapIssueInfo } from './mappers'
import type { LocalGitExecOptions, OwnerRepo } from './gh-utils'
import { githubApiHostArgs, resolveGitHubApiRepository } from './github-api-repository'
import { githubHostExecOptions, resolveGitHubApiRepository } from './github-api-repository'
// prettier-ignore
import { ghExecFileAsync, acquire, release, getIssueOwnerRepo, resolveIssueSource, classifyGhError, classifyListIssuesError, ghRepoExecOptions, githubRepoContext, extractExecError } from './gh-utils'
@@ -411,19 +411,18 @@ export async function addIssueComment(
localGitOptions: LocalGitExecOptions = {}
): Promise<GitHubCommentResult> {
const context = githubRepoContext(repoPath, connectionId, localGitOptions)
const ghOptions = ghRepoExecOptions(context)
const ownerRepo = ownerRepoOverride
? await resolveGitHubApiRepository(repoPath, ownerRepoOverride, connectionId, localGitOptions)
: await getIssueOwnerRepo(repoPath, connectionId, localGitOptions)
if (!ownerRepo) {
return { ok: false, error: 'Could not resolve GitHub owner/repo for this repository' }
}
const ghOptions = { ...ghRepoExecOptions(context), ...githubHostExecOptions(ownerRepo) }
await acquire()
try {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'-X',
'POST',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues/${issueNumber}/comments`,
@@ -1,5 +1,7 @@
import { ghExecFileAsync } from './gh-utils'
import { noteRateLimitSpend, rateLimitGuard } from './rate-limit'
import { noteRepositoryRateLimitSpend, repositoryRateLimitGuard } from './rate-limit'
import { githubHostExecOptions } from './github-api-repository'
import { githubRepoIdentityKey } from '../../shared/github-repository-identity-key'
import type { OwnerRepo } from './github-repository-identity'
type GhExecOptions = Parameters<typeof ghExecFileAsync>[1]
@@ -59,7 +61,8 @@ export async function isCommitPartOfMergedPR(args: {
}
const owner = args.ownerRepo.owner
const repo = args.ownerRepo.repo
const cacheKey = `${owner.toLowerCase()}/${repo.toLowerCase()}#${args.prNumber}@${oid}`
const cacheKey = `${githubRepoIdentityKey(args.ownerRepo)}#${args.prNumber}@${oid}`
const ghOptions = { ...args.ghOptions, ...githubHostExecOptions(args.ownerRepo) }
const now = Date.now()
pruneMergedPRCommitMembershipCache(now)
const cached = membershipCache.get(cacheKey)
@@ -68,7 +71,7 @@ export async function isCommitPartOfMergedPR(args: {
}
// Why blocked stays unknown: hiding a transient branch match is safe, but
// callers must not clear a durable linked PR when the probe never ran.
if (rateLimitGuard('core').blocked) {
if (repositoryRateLimitGuard(args.ownerRepo, 'core', ghOptions).blocked) {
return 'unknown'
}
try {
@@ -79,20 +82,20 @@ export async function isCommitPartOfMergedPR(args: {
// found (contained) or a short page proves absence (not-contained); only the
// pathological all-full case up to the cap stays 'unknown'.
for (let page = 1; page <= COMMIT_PULLS_MAX_PAGES; page += 1) {
if (page > 1 && rateLimitGuard('core').blocked) {
if (page > 1 && repositoryRateLimitGuard(args.ownerRepo, 'core', ghOptions).blocked) {
membershipCache.set(cacheKey, {
value: 'unknown',
expiresAt: now + MEMBERSHIP_ERROR_TTL_MS
})
return 'unknown'
}
noteRateLimitSpend('core')
noteRepositoryRateLimitSpend(args.ownerRepo, 'core', 1, ghOptions)
const { stdout } = await ghExecFileAsync(
[
'api',
`repos/${owner}/${repo}/commits/${oid}/pulls?per_page=${COMMIT_PULLS_PAGE_SIZE}&page=${page}`
],
args.ghOptions
ghOptions
)
const parsed = JSON.parse(stdout) as unknown
// Why: a non-array success payload is a shape mismatch, not an empty page;
+93 -5
View File
@@ -13,7 +13,15 @@ vi.mock('./gh-utils', () => ({
release: vi.fn()
}))
import { getRateLimit, rateLimitGuard, _resetRateLimitCache } from './rate-limit'
import {
getRateLimit,
rateLimitGuard,
noteRateLimitSpend,
spendsSharedGitHubComQuota,
repositoryRateLimitGuard,
noteRepositoryRateLimitSpend,
_resetRateLimitCache
} from './rate-limit'
const PAYLOAD = JSON.stringify({
resources: {
@@ -49,10 +57,12 @@ describe('getRateLimit', () => {
fetchedAt: 1_000
}
})
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(
['api', '--hostname', 'github.com', 'rate_limit'],
{ encoding: 'utf-8' }
)
// The runner injects --hostname at spawn from the `host` option, so the
// probe passes bare argv and pins the host to github.com through options.
expect(ghExecFileAsyncMock).toHaveBeenCalledWith(['api', 'rate_limit'], {
encoding: 'utf-8',
host: 'github.com'
})
})
it('caches a failed probe for the TTL instead of re-spawning gh', async () => {
@@ -139,3 +149,81 @@ describe('rateLimitGuard', () => {
expect(rateLimitGuard('core')).toEqual({ blocked: false })
})
})
// Why: only default github.com traffic on the native runtime shares this
// snapshot's budget. GHES hosts and WSL distros run against separate quotas,
// so the shared guard must bypass them entirely.
describe('shared-quota host scoping', () => {
beforeEach(() => {
vi.useFakeTimers()
vi.setSystemTime(1_000)
ghExecFileAsyncMock.mockReset()
_resetRateLimitCache()
})
afterEach(() => {
vi.useRealTimers()
})
async function cacheExhaustedSnapshot(resetEpochSeconds: number): Promise<void> {
ghExecFileAsyncMock.mockResolvedValueOnce({
stdout: JSON.stringify({
resources: {
core: { limit: 5000, remaining: 3, reset: resetEpochSeconds },
search: { limit: 30, remaining: 28, reset: resetEpochSeconds },
graphql: { limit: 5000, remaining: 4900, reset: resetEpochSeconds }
}
})
})
expect((await getRateLimit()).ok).toBe(true)
}
it('treats github.com / no host on the native runtime as sharing the budget', () => {
expect(spendsSharedGitHubComQuota(undefined)).toBe(true)
expect(spendsSharedGitHubComQuota(null)).toBe(true)
expect(spendsSharedGitHubComQuota({ host: 'github.com' })).toBe(true)
expect(spendsSharedGitHubComQuota({ host: 'GitHub.com' })).toBe(true)
})
it('excludes GHES hosts and WSL runtimes from the shared budget', () => {
expect(spendsSharedGitHubComQuota({ host: 'github.acme-corp.com' })).toBe(false)
expect(spendsSharedGitHubComQuota({ host: 'github.com' }, { wslDistro: 'Ubuntu' })).toBe(false)
expect(spendsSharedGitHubComQuota(undefined, { wslDistro: 'Ubuntu' })).toBe(false)
})
it('applies the shared guard for github.com but bypasses non-shared scopes', async () => {
await cacheExhaustedSnapshot(61)
expect(repositoryRateLimitGuard({ host: 'github.com' }, 'core')).toEqual({
blocked: true,
remaining: 3,
limit: 5000,
resetAt: 61
})
expect(repositoryRateLimitGuard({ host: 'github.acme-corp.com' }, 'core')).toEqual({
blocked: false
})
expect(
repositoryRateLimitGuard({ host: 'github.com' }, 'core', { wslDistro: 'Ubuntu' })
).toEqual({ blocked: false })
})
it('debits shared-budget spend but no-ops for non-shared scopes', async () => {
await cacheExhaustedSnapshot(61)
noteRepositoryRateLimitSpend({ host: 'github.acme-corp.com' }, 'core')
const afterEnterprise = rateLimitGuard('core')
expect(afterEnterprise.blocked && afterEnterprise.remaining).toBe(3)
noteRepositoryRateLimitSpend({ host: 'github.com' }, 'core')
const afterShared = rateLimitGuard('core')
expect(afterShared.blocked && afterShared.remaining).toBe(2)
})
it('matches noteRateLimitSpend when the scope is shared github.com', async () => {
await cacheExhaustedSnapshot(61)
noteRateLimitSpend('core')
const guard = rateLimitGuard('core')
expect(guard.blocked && guard.remaining).toBe(2)
})
})
+36 -2
View File
@@ -160,6 +160,39 @@ export function noteRateLimitSpend(bucket: RateLimitBucketKind, cost = 1): void
}
}
// Why: this module's snapshot describes the default github.com account on the
// native runtime only. GHES and WSL traffic runs against other quotas, so it
// must neither consult nor debit the shared budget (the runner's per-scope
// breaker still protects those hosts after a real 403).
export function spendsSharedGitHubComQuota(
repository: { host?: string } | null | undefined,
executionOptions?: { wslDistro?: string }
): boolean {
const host = repository?.host
return (!host || host.toLowerCase() === 'github.com') && !executionOptions?.wslDistro
}
export function repositoryRateLimitGuard(
repository: { host?: string } | null | undefined,
bucket: RateLimitBucketKind,
executionOptions?: { wslDistro?: string }
): ReturnType<typeof rateLimitGuard> {
return spendsSharedGitHubComQuota(repository, executionOptions)
? rateLimitGuard(bucket)
: { blocked: false }
}
export function noteRepositoryRateLimitSpend(
repository: { host?: string } | null | undefined,
bucket: RateLimitBucketKind,
cost = 1,
executionOptions?: { wslDistro?: string }
): void {
if (spendsSharedGitHubComQuota(repository, executionOptions)) {
noteRateLimitSpend(bucket, cost)
}
}
// Why: when the runner's breaker trips it only knows "blocked", not for how
// long. `gh api rate_limit` is exempt from limits, so one forced probe turns
// the fallback block into the bucket's real reset time (or clears a block
@@ -224,8 +257,9 @@ async function fetchRateLimitSnapshot(): Promise<GetRateLimitResult> {
try {
// Why: this singleton snapshot guards native github.com traffic. Pin the
// host so a process-level GH_HOST cannot make it describe a GHES account.
const { stdout } = await ghExecFileAsync(['api', '--hostname', 'github.com', 'rate_limit'], {
encoding: 'utf-8'
const { stdout } = await ghExecFileAsync(['api', 'rate_limit'], {
encoding: 'utf-8',
host: 'github.com'
})
const parsed = JSON.parse(stdout) as GhRateLimitPayload
const snapshot: GitHubRateLimitSnapshot = {
@@ -13,6 +13,8 @@ const {
getPRCommentsMock,
rateLimitGuardMock,
noteRateLimitSpendMock,
repositoryRateLimitGuardMock,
noteRepositoryRateLimitSpendMock,
acquireMock,
releaseMock
} = vi.hoisted(() => ({
@@ -24,6 +26,8 @@ const {
getPRCommentsMock: vi.fn(),
rateLimitGuardMock: vi.fn<() => RateLimitGuardResult>(() => ({ blocked: false })),
noteRateLimitSpendMock: vi.fn(),
repositoryRateLimitGuardMock: vi.fn<() => RateLimitGuardResult>(() => ({ blocked: false })),
noteRepositoryRateLimitSpendMock: vi.fn(),
acquireMock: vi.fn(),
releaseMock: vi.fn()
}))
@@ -50,7 +54,9 @@ vi.mock('./client', () => ({
vi.mock('./rate-limit', () => ({
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: noteRateLimitSpendMock
noteRateLimitSpend: noteRateLimitSpendMock,
repositoryRateLimitGuard: repositoryRateLimitGuardMock,
noteRepositoryRateLimitSpend: noteRepositoryRateLimitSpendMock
}))
import { getWorkItemDetails } from './work-item-details'
@@ -66,6 +72,9 @@ describe('getWorkItemDetails PR file viewed state', () => {
rateLimitGuardMock.mockReset()
rateLimitGuardMock.mockReturnValue({ blocked: false })
noteRateLimitSpendMock.mockReset()
repositoryRateLimitGuardMock.mockReset()
repositoryRateLimitGuardMock.mockReturnValue({ blocked: false })
noteRepositoryRateLimitSpendMock.mockReset()
acquireMock.mockReset()
releaseMock.mockReset()
acquireMock.mockResolvedValue(undefined)
@@ -41,7 +41,9 @@ vi.mock('./github-enterprise-repository', () => ({
vi.mock('./rate-limit', () => ({
rateLimitGuard: vi.fn(() => ({ blocked: false })),
noteRateLimitSpend: vi.fn()
noteRateLimitSpend: vi.fn(),
repositoryRateLimitGuard: vi.fn(() => ({ blocked: false })),
noteRepositoryRateLimitSpend: vi.fn()
}))
import { getWorkItemDetails } from './work-item-details'
+27 -8
View File
@@ -15,6 +15,8 @@ const {
getPRCommentsMock,
rateLimitGuardMock,
noteRateLimitSpendMock,
repositoryRateLimitGuardMock,
noteRepositoryRateLimitSpendMock,
ghRepoExecOptionsMock,
githubRepoContextMock,
acquireMock,
@@ -30,6 +32,8 @@ const {
getPRCommentsMock: vi.fn(),
rateLimitGuardMock: vi.fn<() => RateLimitGuardResult>(() => ({ blocked: false })),
noteRateLimitSpendMock: vi.fn(),
repositoryRateLimitGuardMock: vi.fn<() => RateLimitGuardResult>(() => ({ blocked: false })),
noteRepositoryRateLimitSpendMock: vi.fn(),
ghRepoExecOptionsMock: vi.fn((context) =>
context.connectionId
? {}
@@ -67,7 +71,9 @@ vi.mock('./github-enterprise-repository', () => ({
vi.mock('./rate-limit', () => ({
rateLimitGuard: rateLimitGuardMock,
noteRateLimitSpend: noteRateLimitSpendMock
noteRateLimitSpend: noteRateLimitSpendMock,
repositoryRateLimitGuard: repositoryRateLimitGuardMock,
noteRepositoryRateLimitSpend: noteRepositoryRateLimitSpendMock
}))
import { getPRFileContents, getWorkItemDetails } from './work-item-details'
@@ -86,6 +92,9 @@ describe('getWorkItemDetails', () => {
rateLimitGuardMock.mockReset()
rateLimitGuardMock.mockReturnValue({ blocked: false })
noteRateLimitSpendMock.mockReset()
repositoryRateLimitGuardMock.mockReset()
repositoryRateLimitGuardMock.mockReturnValue({ blocked: false })
noteRepositoryRateLimitSpendMock.mockReset()
ghRepoExecOptionsMock.mockClear()
githubRepoContextMock.mockClear()
acquireMock.mockReset()
@@ -410,12 +419,20 @@ describe('getWorkItemDetails', () => {
})
it('skips optional GraphQL issue detail calls when the cached GraphQL budget is low', async () => {
// github.com repos share the singleton quota, so both the raw and
// repository-scoped guards report the same low-budget block.
rateLimitGuardMock.mockReturnValue({
blocked: true,
remaining: 3,
limit: 5000,
resetAt: 1_800_000_000
})
repositoryRateLimitGuardMock.mockReturnValue({
blocked: true,
remaining: 3,
limit: 5000,
resetAt: 1_800_000_000
})
getWorkItemMock.mockResolvedValueOnce({
id: 'issue:923',
type: 'issue',
@@ -438,6 +455,7 @@ describe('getWorkItemDetails', () => {
expect(ghExecFileAsyncMock).toHaveBeenCalledTimes(3)
expect(ghExecFileAsyncMock.mock.calls.some((call) => call[0][1] === 'graphql')).toBe(false)
expect(noteRateLimitSpendMock).not.toHaveBeenCalled()
expect(noteRepositoryRateLimitSpendMock).not.toHaveBeenCalled()
expect(details?.body).toBe('Issue body')
expect(details?.participants).toEqual([])
})
@@ -687,12 +705,11 @@ describe('getWorkItemDetails', () => {
.map(([args]) => args as string[])
.filter((args) => args[0] === 'api')
expect(apiCalls.length).toBeGreaterThan(0)
expect(apiCalls.every((args) => args.includes('--hostname'))).toBe(true)
expect(apiCalls.every((args) => !args.includes('--hostname'))).toBe(true)
expect(
apiCalls.every((args) => args[args.indexOf('--hostname') + 1] === 'github.acme-corp.com')
).toBe(true)
expect(
ghExecFileAsyncMock.mock.calls.every(([, options]) => Object.keys(options).length === 0)
ghExecFileAsyncMock.mock.calls.every(
([, options]) => options?.host === 'github.acme-corp.com'
)
).toBe(true)
})
@@ -768,9 +785,11 @@ describe('getWorkItemDetails', () => {
})
const apiCalls = ghExecFileAsyncMock.mock.calls.map(([args]) => args as string[])
expect(apiCalls).toHaveLength(2)
expect(apiCalls.every((args) => args.includes('--hostname'))).toBe(true)
expect(apiCalls.every((args) => !args.includes('--hostname'))).toBe(true)
expect(
apiCalls.every((args) => args[args.indexOf('--hostname') + 1] === 'github.acme-corp.com')
ghExecFileAsyncMock.mock.calls.every(
([, options]) => options?.host === 'github.acme-corp.com'
)
).toBe(true)
})
+31 -48
View File
@@ -25,11 +25,16 @@ import {
import { getWorkItem, getWorkItemByOwnerRepo, getPRChecks, getPRComments } from './client'
import {
getOriginGitHubApiRepository,
githubApiHostArgs,
githubHostExecOptions,
isGitHubDotComRepository,
type GitHubApiRepository
} from './github-api-repository'
import { noteRateLimitSpend, rateLimitGuard } from './rate-limit'
import {
noteRateLimitSpend,
noteRepositoryRateLimitSpend,
rateLimitGuard,
repositoryRateLimitGuard
} from './rate-limit'
import { getPRReviewCommentLineNumbersFromPatch } from './pr-review-comment-lines'
import { isMaxBufferOverflowError } from '../git/max-buffer-overflow'
@@ -54,27 +59,6 @@ function encodeGitHubContentPath(path: string): string {
return path.split('/').map(encodeURIComponent).join('/')
}
function repositoryRateLimitGuard(
repository: GitHubApiRepository | null,
bucket: 'core' | 'graphql' | 'search',
executionOptions: Pick<LocalGitExecOptions, 'wslDistro'> = {}
): ReturnType<typeof rateLimitGuard> {
return (!repository || isGitHubDotComRepository(repository)) && !executionOptions.wslDistro
? rateLimitGuard(bucket)
: { blocked: false }
}
function noteRepositoryRateLimitSpend(
repository: GitHubApiRepository | null,
bucket: 'core' | 'graphql' | 'search',
cost = 1,
executionOptions: Pick<LocalGitExecOptions, 'wslDistro'> = {}
): void {
if ((!repository || isGitHubDotComRepository(repository)) && !executionOptions.wslDistro) {
noteRateLimitSpend(bucket, cost)
}
}
const PR_FILE_VIEWED_STATES_QUERY = `query($owner: String!, $repo: String!, $number: Int!, $after: String) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
@@ -320,14 +304,13 @@ async function getIssueTimelineItems(
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'--cache',
'60s',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/issues/${issueNumber}/timeline?per_page=${GITHUB_REST_PAGE_SIZE}&page=${page}`,
'--jq',
'.[] | @json'
],
ghOptions
{ ...ghOptions, ...githubHostExecOptions(ownerRepo) }
)
// Why: --jq emits compact NDJSON while explicit pages let us stop once
// supported activity reaches the drawer cap.
@@ -535,17 +518,14 @@ async function getPRMetadata(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<{ body: string; headSha?: string; baseSha?: string }> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
try {
if (ownerRepo) {
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'--cache',
'60s',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${prNumber}`
],
['api', '--cache', '60s', `repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${prNumber}`],
ghOptions
)
const data = JSON.parse(stdout) as {
@@ -588,10 +568,13 @@ async function getPRFiles(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<GitHubPRFile[] | null> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
if (!ownerRepo) {
return null
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
try {
const data: RESTPRFile[] = []
for (let page = 1; data.length < MAX_PR_FILES; page += 1) {
@@ -599,7 +582,6 @@ async function getPRFiles(
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'--cache',
'60s',
`repos/${ownerRepo.owner}/${ownerRepo.repo}/pulls/${prNumber}/files?per_page=100${pageSuffix}`
@@ -638,10 +620,13 @@ async function getPRFileViewedStates(
connectionId?: string | null,
localGitOptions: LocalGitExecOptions = {}
): Promise<PRFileViewedStatesResult | null> {
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
if (!ownerRepo) {
return null
}
const ghOptions = {
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
if (repositoryRateLimitGuard(ownerRepo, 'graphql', localGitOptions).blocked) {
return null
}
@@ -653,7 +638,6 @@ async function getPRFileViewedStates(
for (let fetched = 0; fetched < MAX_PR_FILES; fetched += 100) {
const args = [
'api',
...githubApiHostArgs(ownerRepo),
'graphql',
'-f',
`query=${PR_FILE_VIEWED_STATES_QUERY}`,
@@ -846,7 +830,6 @@ async function getWorkItemParticipants(
const { stdout } = await ghExecFileAsync(
[
'api',
...githubApiHostArgs(ownerRepo),
'graphql',
'-f',
`query=${WORK_ITEM_PARTICIPANTS_QUERY}`,
@@ -859,7 +842,10 @@ async function getWorkItemParticipants(
'-F',
`isPr=${item.type === 'pr'}`
],
ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
{
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(ownerRepo)
}
)
const data = JSON.parse(stdout) as {
data?: {
@@ -920,14 +906,11 @@ async function getGitHubUsersByLogin(
try {
noteRepositoryRateLimitSpend(repository, 'graphql', 1, localGitOptions)
const { stdout } = await ghExecFileAsync(
[
'api',
...(repository ? githubApiHostArgs(repository) : []),
'graphql',
'-f',
`query=query { ${fields} }`
],
ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
['api', 'graphql', '-f', `query=query { ${fields} }`],
{
...ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions)),
...githubHostExecOptions(repository)
}
)
const data = JSON.parse(stdout) as {
data?: Record<
@@ -1270,13 +1253,13 @@ async function fetchContentAtRef(args: {
'300s',
'-H',
'Accept: application/vnd.github.raw',
...githubApiHostArgs(args.ownerRepo),
`repos/${args.ownerRepo.owner}/${args.ownerRepo.repo}/contents/${encodeGitHubContentPath(args.path)}?ref=${encodeURIComponent(args.ref)}`
],
{
...ghRepoExecOptions(
githubRepoContext(args.repoPath, args.connectionId, args.localGitOptions)
),
...githubHostExecOptions(args.ownerRepo),
maxBuffer: GITHUB_RAW_CONTENT_MAX_BUFFER_BYTES
}
)