From e9f79850be5b5c2aa79faf3879a0cda74ebd3b0e Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sat, 11 Jul 2026 19:26:17 -0700 Subject: [PATCH] Distinguish failed PR file fetches from genuinely empty PRs and add a re (#8342) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/main/github/work-item-details.test.ts | 70 +++++++++++++++++++ src/main/github/work-item-details.ts | 14 ++-- .../src/components/GitHubItemDialog.tsx | 16 +++++ .../src/components/PullRequestPage.tsx | 16 +++++ src/renderer/src/i18n/locales/en.json | 4 ++ src/renderer/src/i18n/locales/es.json | 2 + src/renderer/src/i18n/locales/ja.json | 2 + src/renderer/src/i18n/locales/ko.json | 2 + src/renderer/src/i18n/locales/zh.json | 2 + src/shared/types.ts | 3 + 10 files changed, 127 insertions(+), 4 deletions(-) diff --git a/src/main/github/work-item-details.test.ts b/src/main/github/work-item-details.test.ts index 69504b92f..6d3d14c99 100644 --- a/src/main/github/work-item-details.test.ts +++ b/src/main/github/work-item-details.test.ts @@ -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([]) + }) }) diff --git a/src/main/github/work-item-details.ts b/src/main/github/work-item-details.ts index 6029613fb..9aa2de2b2 100644 --- a/src/main/github/work-item-details.ts +++ b/src/main/github/work-item-details.ts @@ -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 { +): Promise { 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 { diff --git a/src/renderer/src/components/GitHubItemDialog.tsx b/src/renderer/src/components/GitHubItemDialog.tsx index 5de98f93e..1cf6f7bea 100644 --- a/src/renderer/src/components/GitHubItemDialog.tsx +++ b/src/renderer/src/components/GitHubItemDialog.tsx @@ -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>(() => new Set()) // Why: clipboard IPC can resolve after the dialog unmounts; skip copied-state @@ -7785,6 +7786,21 @@ export default function GitHubItemDialog({
+ ) : filesUnavailable && files.length === 0 ? ( + // Why: the file fetch failed (rate limit, auth, unresolved + // remote); offer a retry instead of implying the PR is empty. +
+
+ {translate( + 'auto.components.GitHubItemDialog.filesUnavailable', + "Couldn't load changed files." + )} +
+ +
) : files.length === 0 ? (
{translate( diff --git a/src/renderer/src/components/PullRequestPage.tsx b/src/renderer/src/components/PullRequestPage.tsx index c6693d153..cbe4d8861 100644 --- a/src/renderer/src/components/PullRequestPage.tsx +++ b/src/renderer/src/components/PullRequestPage.tsx @@ -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>(() => new Set()) // Why: clipboard IPC can resolve after the page unmounts; skip copied-state @@ -7319,6 +7320,21 @@ export default function PullRequestPage({
+ ) : filesUnavailable && files.length === 0 ? ( + // Why: the file fetch failed (rate limit, auth, unresolved + // remote); offer a retry instead of implying the PR is empty. +
+
+ {translate( + 'auto.components.PullRequestPage.filesUnavailable', + "Couldn't load changed files." + )} +
+ +
) : files.length === 0 ? (
{translate('auto.components.PullRequestPage.6ad2c1ab9c', 'No files changed.')} diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 22e81f486..60a8b037a 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -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", diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index 4fd95f6c3..0bc3bab04 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -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", diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index b5092c297..499d14e3d 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -722,6 +722,8 @@ "GitHubItemDialog": { "3ab6ac0fc8": "選択した GitHub Issue または PR をプレビュー・編集します。", "3cd5ae5b7b": "ファイルは変更されませんでした。", + "filesUnavailable": "変更されたファイルを読み込めませんでした。", + "filesRetry": "再試行", "999b5ad7d9": "ファイル", "4bd1f5b055": "チェック", "e30a5470c9": "会話", diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index 2d7922995..921ae5085 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -722,6 +722,8 @@ "GitHubItemDialog": { "3ab6ac0fc8": "선택한 GitHub 이슈 또는 PR을 미리보기하고 편집합니다.", "3cd5ae5b7b": "변경된 파일이 없습니다.", + "filesUnavailable": "변경된 파일을 불러올 수 없습니다.", + "filesRetry": "재시도", "999b5ad7d9": "파일", "4bd1f5b055": "체크", "e30a5470c9": "대화", diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index aa8b6c23f..f2de62ad9 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -722,6 +722,8 @@ "GitHubItemDialog": { "3ab6ac0fc8": "预览并编辑选定的 GitHub 议题或拉取请求。", "3cd5ae5b7b": "没有更改任何文件。", + "filesUnavailable": "无法加载更改的文件。", + "filesRetry": "重试", "999b5ad7d9": "文件", "4bd1f5b055": "检查项", "e30a5470c9": "对话", diff --git a/src/shared/types.ts b/src/shared/types.ts index 882ddb2a2..06573cb99 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -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[]