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 {
|
||||
|
||||
@@ -7088,6 +7088,7 @@ export default function GitHubItemDialog({
|
||||
const comments = details?.comments ?? []
|
||||
const timelineItems = details?.timelineItems ?? []
|
||||
const files = details?.files ?? []
|
||||
const filesUnavailable = details?.filesUnavailable ?? false
|
||||
const checks = details?.checks ?? []
|
||||
const [pendingViewedPaths, setPendingViewedPaths] = useState<Set<string>>(() => new Set())
|
||||
// Why: clipboard IPC can resolve after the dialog unmounts; skip copied-state
|
||||
@@ -7785,6 +7786,21 @@ export default function GitHubItemDialog({
|
||||
<div className="flex items-center justify-center py-10">
|
||||
<LoaderCircle className="size-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : filesUnavailable && files.length === 0 ? (
|
||||
// Why: the file fetch failed (rate limit, auth, unresolved
|
||||
// remote); offer a retry instead of implying the PR is empty.
|
||||
<div className="flex flex-col items-center gap-3 px-4 py-10 text-center">
|
||||
<div className="text-[12px] text-muted-foreground">
|
||||
{translate(
|
||||
'auto.components.GitHubItemDialog.filesUnavailable',
|
||||
"Couldn't load changed files."
|
||||
)}
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={invalidateCurrentDetailsCache}>
|
||||
<RefreshCw className="size-3.5" />
|
||||
{translate('auto.components.GitHubItemDialog.filesRetry', 'Retry')}
|
||||
</Button>
|
||||
</div>
|
||||
) : files.length === 0 ? (
|
||||
<div className="px-4 py-10 text-center text-[12px] text-muted-foreground">
|
||||
{translate(
|
||||
|
||||
@@ -6807,6 +6807,7 @@ export default function PullRequestPage({
|
||||
const body = details?.body ?? ''
|
||||
const comments = details?.comments ?? []
|
||||
const files = details?.files ?? []
|
||||
const filesUnavailable = details?.filesUnavailable ?? false
|
||||
const checks = details?.checks ?? []
|
||||
const [pendingViewedPaths, setPendingViewedPaths] = useState<Set<string>>(() => new Set())
|
||||
// Why: clipboard IPC can resolve after the page unmounts; skip copied-state
|
||||
@@ -7319,6 +7320,21 @@ export default function PullRequestPage({
|
||||
<div className="flex items-center justify-center py-10">
|
||||
<LoaderCircle className="size-5 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : filesUnavailable && files.length === 0 ? (
|
||||
// Why: the file fetch failed (rate limit, auth, unresolved
|
||||
// remote); offer a retry instead of implying the PR is empty.
|
||||
<div className="flex flex-col items-center gap-3 px-4 py-10 text-center">
|
||||
<div className="text-[12px] text-muted-foreground">
|
||||
{translate(
|
||||
'auto.components.PullRequestPage.filesUnavailable',
|
||||
"Couldn't load changed files."
|
||||
)}
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={invalidateCurrentDetailsCache}>
|
||||
<RefreshCw className="size-3.5" />
|
||||
{translate('auto.components.PullRequestPage.filesRetry', 'Retry')}
|
||||
</Button>
|
||||
</div>
|
||||
) : files.length === 0 ? (
|
||||
<div className="px-4 py-10 text-center text-[12px] text-muted-foreground">
|
||||
{translate('auto.components.PullRequestPage.6ad2c1ab9c', 'No files changed.')}
|
||||
|
||||
@@ -722,6 +722,8 @@
|
||||
"GitHubItemDialog": {
|
||||
"3ab6ac0fc8": "Preview and edit the selected GitHub issue or pull request.",
|
||||
"3cd5ae5b7b": "No files changed.",
|
||||
"filesUnavailable": "Couldn't load changed files.",
|
||||
"filesRetry": "Retry",
|
||||
"999b5ad7d9": "Files",
|
||||
"4bd1f5b055": "Checks",
|
||||
"e30a5470c9": "Conversation",
|
||||
@@ -1217,6 +1219,8 @@
|
||||
"2560588245": "Failed to request reviewer",
|
||||
"3450247584": "Comment",
|
||||
"6ad2c1ab9c": "No files changed.",
|
||||
"filesUnavailable": "Couldn't load changed files.",
|
||||
"filesRetry": "Retry",
|
||||
"4d18310d55": "Files changed",
|
||||
"94d95cf1f7": "Checks",
|
||||
"9e8d45700e": "Conversation",
|
||||
|
||||
@@ -722,6 +722,8 @@
|
||||
"GitHubItemDialog": {
|
||||
"3ab6ac0fc8": "Previsualiza y edita el issue o pull request de GitHub seleccionado.",
|
||||
"3cd5ae5b7b": "No se cambiaron archivos.",
|
||||
"filesUnavailable": "No se pudieron cargar los archivos modificados.",
|
||||
"filesRetry": "Reintentar",
|
||||
"999b5ad7d9": "Archivos",
|
||||
"4bd1f5b055": "Checks",
|
||||
"e30a5470c9": "Conversación",
|
||||
|
||||
@@ -722,6 +722,8 @@
|
||||
"GitHubItemDialog": {
|
||||
"3ab6ac0fc8": "選択した GitHub Issue または PR をプレビュー・編集します。",
|
||||
"3cd5ae5b7b": "ファイルは変更されませんでした。",
|
||||
"filesUnavailable": "変更されたファイルを読み込めませんでした。",
|
||||
"filesRetry": "再試行",
|
||||
"999b5ad7d9": "ファイル",
|
||||
"4bd1f5b055": "チェック",
|
||||
"e30a5470c9": "会話",
|
||||
|
||||
@@ -722,6 +722,8 @@
|
||||
"GitHubItemDialog": {
|
||||
"3ab6ac0fc8": "선택한 GitHub 이슈 또는 PR을 미리보기하고 편집합니다.",
|
||||
"3cd5ae5b7b": "변경된 파일이 없습니다.",
|
||||
"filesUnavailable": "변경된 파일을 불러올 수 없습니다.",
|
||||
"filesRetry": "재시도",
|
||||
"999b5ad7d9": "파일",
|
||||
"4bd1f5b055": "체크",
|
||||
"e30a5470c9": "대화",
|
||||
|
||||
@@ -722,6 +722,8 @@
|
||||
"GitHubItemDialog": {
|
||||
"3ab6ac0fc8": "预览并编辑选定的 GitHub 议题或拉取请求。",
|
||||
"3cd5ae5b7b": "没有更改任何文件。",
|
||||
"filesUnavailable": "无法加载更改的文件。",
|
||||
"filesRetry": "重试",
|
||||
"999b5ad7d9": "文件",
|
||||
"4bd1f5b055": "检查项",
|
||||
"e30a5470c9": "对话",
|
||||
|
||||
@@ -1529,6 +1529,9 @@ export type GitHubWorkItemDetails = {
|
||||
pullRequestId?: string
|
||||
checks?: PRCheckDetail[]
|
||||
files?: GitHubPRFile[]
|
||||
/** Only set for PRs. True when the file fetch failed (rate limit, auth,
|
||||
* unresolved remote) rather than the PR genuinely having no changed files. */
|
||||
filesUnavailable?: boolean
|
||||
participants?: GitHubAssignableUser[]
|
||||
/** Logins of current assignees. Only set for issues. */
|
||||
assignees?: string[]
|
||||
|
||||
Reference in New Issue
Block a user