Distinguish failed PR file fetches from genuinely empty PRs and add a re (#8342)
- gh file-fetch failures (rate limit, auth, unresolved remote) previously returned an empty array, which the Files tab rendered as "No files changed." — indistinguishable from a real empty PR - getPRFiles now returns null on failure; work-item-details surfaces this as filesUnavailable so GitHubItemDialog and PullRequestPage can show a retry action instead of a misleading empty state
This commit is contained in:
@@ -498,4 +498,74 @@ describe('getWorkItemDetails', () => {
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
// Why: a rate-limited/auth-failed file fetch must not render as an empty PR;
|
||||
// the Files tab keys its retry state off details.filesUnavailable.
|
||||
it('flags filesUnavailable when the PR file fetch fails but leaves the PR empty otherwise intact', async () => {
|
||||
getWorkItemMock.mockResolvedValueOnce({
|
||||
id: 'pr:8305',
|
||||
type: 'pr',
|
||||
number: 8305,
|
||||
title: 'Files fetch fails',
|
||||
state: 'open',
|
||||
url: 'https://github.com/acme/widgets/pull/8305',
|
||||
labels: [],
|
||||
updatedAt: '2026-07-11T00:00:00Z',
|
||||
author: 'pr-author'
|
||||
})
|
||||
getOwnerRepoMock.mockResolvedValue({ owner: 'acme', repo: 'widgets' })
|
||||
getPRCommentsMock.mockResolvedValue([])
|
||||
getPRChecksMock.mockResolvedValue([])
|
||||
ghExecFileAsyncMock.mockImplementation(async (args: string[]) => {
|
||||
const target = args.at(-1)
|
||||
if (target === 'repos/acme/widgets/pulls/8305') {
|
||||
return {
|
||||
stdout: JSON.stringify({ head: { sha: 'head-sha' }, base: { sha: 'base-sha' } })
|
||||
}
|
||||
}
|
||||
if (target === 'repos/acme/widgets/pulls/8305/files?per_page=100') {
|
||||
throw new Error('gh: API rate limit exceeded (403)')
|
||||
}
|
||||
return { stdout: JSON.stringify({ data: {} }) }
|
||||
})
|
||||
|
||||
const details = await getWorkItemDetails('/repo-root', 8305, 'pr')
|
||||
|
||||
expect(details?.filesUnavailable).toBe(true)
|
||||
expect(details?.files).toBeUndefined()
|
||||
})
|
||||
|
||||
it('treats an empty file list as a genuinely empty PR, not an unavailable one', async () => {
|
||||
getWorkItemMock.mockResolvedValueOnce({
|
||||
id: 'pr:8306',
|
||||
type: 'pr',
|
||||
number: 8306,
|
||||
title: 'Empty PR',
|
||||
state: 'open',
|
||||
url: 'https://github.com/acme/widgets/pull/8306',
|
||||
labels: [],
|
||||
updatedAt: '2026-07-11T00:00:00Z',
|
||||
author: 'pr-author'
|
||||
})
|
||||
getOwnerRepoMock.mockResolvedValue({ owner: 'acme', repo: 'widgets' })
|
||||
getPRCommentsMock.mockResolvedValue([])
|
||||
getPRChecksMock.mockResolvedValue([])
|
||||
ghExecFileAsyncMock.mockImplementation(async (args: string[]) => {
|
||||
const target = args.at(-1)
|
||||
if (target === 'repos/acme/widgets/pulls/8306') {
|
||||
return {
|
||||
stdout: JSON.stringify({ head: { sha: 'head-sha' }, base: { sha: 'base-sha' } })
|
||||
}
|
||||
}
|
||||
if (target === 'repos/acme/widgets/pulls/8306/files?per_page=100') {
|
||||
return { stdout: '[]' }
|
||||
}
|
||||
return { stdout: JSON.stringify({ data: {} }) }
|
||||
})
|
||||
|
||||
const details = await getWorkItemDetails('/repo-root', 8306, 'pr')
|
||||
|
||||
expect(details?.filesUnavailable).toBe(false)
|
||||
expect(details?.files).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -525,12 +525,15 @@ async function getPRHeadBaseSha(
|
||||
}
|
||||
}
|
||||
|
||||
// Why: null signals a failed/blocked fetch (rate limit, auth, unresolved
|
||||
// remote) so the Files tab can show a retryable error instead of the
|
||||
// misleading "No files changed." empty state; [] means a genuinely empty PR.
|
||||
async function getPRFiles(
|
||||
repoPath: string,
|
||||
prNumber: number,
|
||||
connectionId?: string | null,
|
||||
localGitOptions: LocalGitExecOptions = {}
|
||||
): Promise<GitHubPRFile[]> {
|
||||
): Promise<GitHubPRFile[] | null> {
|
||||
const ghOptions = ghRepoExecOptions(githubRepoContext(repoPath, connectionId, localGitOptions))
|
||||
const ownerRepo = await getOwnerRepo(
|
||||
repoPath,
|
||||
@@ -538,7 +541,7 @@ async function getPRFiles(
|
||||
...localGitOptionArgs(localGitOptions)
|
||||
)
|
||||
if (!ownerRepo) {
|
||||
return []
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const { stdout } = await ghExecFileAsync(
|
||||
@@ -561,7 +564,7 @@ async function getPRFiles(
|
||||
reviewCommentLineNumbers: getPRReviewCommentLineNumbersFromPatch(file.patch)
|
||||
}))
|
||||
} catch {
|
||||
return []
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1068,7 +1071,10 @@ export async function getWorkItemDetails(
|
||||
baseSha: shas?.baseSha,
|
||||
pullRequestId: viewedStates?.pullRequestId,
|
||||
checks,
|
||||
files: mergePRFileViewedStates(files, viewedStates),
|
||||
// Why: distinguish a failed file fetch (null) from an empty PR so the
|
||||
// Files tab surfaces a retry instead of "No files changed."
|
||||
files: files === null ? undefined : mergePRFileViewedStates(files, viewedStates),
|
||||
filesUnavailable: files === null,
|
||||
participants: mentionParticipants
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user