From 3e51000bc50c8f3603f3fa82bb5e82490159a732 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Sun, 5 Apr 2026 11:26:32 -0700 Subject: [PATCH] fix: bypass gh CLI HTTP cache on manual PR checks refresh (#308) The `gh api --cache 60s` flag caused stale check-run data even when the user explicitly clicked refresh. Thread a `noCache` flag through IPC so manual refreshes skip the gh CLI cache while polling still benefits from it. --- src/main/github/client.ts | 9 ++++++--- src/main/ipc/github.ts | 6 ++++-- src/preload/index.d.ts | 1 + src/preload/index.ts | 8 ++++++-- src/renderer/src/store/slices/github.ts | 3 ++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/github/client.ts b/src/main/github/client.ts index a9ef3ea1509..148c5d71ad3 100644 --- a/src/main/github/client.ts +++ b/src/main/github/client.ts @@ -120,18 +120,21 @@ export async function getPRForBranch(repoPath: string, branch: string): Promise< export async function getPRChecks( repoPath: string, prNumber: number, - branch?: string + branch?: string, + options?: { noCache?: boolean } ): Promise { const ownerRepo = branch ? await getOwnerRepo(repoPath) : null await acquire() try { if (ownerRepo && branch) { + // Why: --cache 60s saves rate-limit budget during polling, but when the + // user explicitly clicks refresh we must skip it so gh fetches fresh data. + const cacheArgs = options?.noCache ? [] : ['--cache', '60s'] const { stdout } = await execFileAsync( 'gh', [ 'api', - '--cache', - '60s', + ...cacheArgs, `repos/${ownerRepo.owner}/${ownerRepo.repo}/commits/${encodeURIComponent(branch)}/check-runs?per_page=100` ], { cwd: repoPath, encoding: 'utf-8' } diff --git a/src/main/ipc/github.ts b/src/main/ipc/github.ts index 39e17b001df..40442f36de2 100644 --- a/src/main/ipc/github.ts +++ b/src/main/ipc/github.ts @@ -37,9 +37,11 @@ export function registerGitHubHandlers(store: Store): void { ipcMain.handle( 'gh:prChecks', - (_event, args: { repoPath: string; prNumber: number; branch?: string }) => { + (_event, args: { repoPath: string; prNumber: number; branch?: string; noCache?: boolean }) => { const repoPath = assertRegisteredRepoPath(args.repoPath, store) - return getPRChecks(repoPath, args.prNumber, args.branch) + return getPRChecks(repoPath, args.prNumber, args.branch, { + noCache: args.noCache + }) } ) diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index 5c9cad66e77..b3cdc0e64c3 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -71,6 +71,7 @@ type GhApi = { repoPath: string prNumber: number branch?: string + noCache?: boolean }) => Promise updatePRTitle: (args: { repoPath: string; prNumber: number; title: string }) => Promise mergePR: (args: { diff --git a/src/preload/index.ts b/src/preload/index.ts index 0492811b6f9..3d6bdf6e96b 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -186,8 +186,12 @@ const api = { listIssues: (args: { repoPath: string; limit?: number }): Promise => ipcRenderer.invoke('gh:listIssues', args), - prChecks: (args: { repoPath: string; prNumber: number; branch?: string }): Promise => - ipcRenderer.invoke('gh:prChecks', args), + prChecks: (args: { + repoPath: string + prNumber: number + branch?: string + noCache?: boolean + }): Promise => ipcRenderer.invoke('gh:prChecks', args), updatePRTitle: (args: { repoPath: string diff --git a/src/renderer/src/store/slices/github.ts b/src/renderer/src/store/slices/github.ts index 69bf594e713..82b1e76a684 100644 --- a/src/renderer/src/store/slices/github.ts +++ b/src/renderer/src/store/slices/github.ts @@ -193,7 +193,8 @@ export const createGitHubSlice: StateCreator = (s const checks = (await window.api.gh.prChecks({ repoPath, prNumber, - branch + branch, + noCache: options?.force })) as PRCheckDetail[] set((s) => { const nextState: Partial = {