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.
This commit is contained in:
Jinjing
2026-04-05 11:26:32 -07:00
committed by GitHub
parent 8a8826b2d6
commit 3e51000bc5
5 changed files with 19 additions and 8 deletions
+6 -3
View File
@@ -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<PRCheckDetail[]> {
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' }
+4 -2
View File
@@ -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
})
}
)
+1
View File
@@ -71,6 +71,7 @@ type GhApi = {
repoPath: string
prNumber: number
branch?: string
noCache?: boolean
}) => Promise<PRCheckDetail[]>
updatePRTitle: (args: { repoPath: string; prNumber: number; title: string }) => Promise<boolean>
mergePR: (args: {
+6 -2
View File
@@ -186,8 +186,12 @@ const api = {
listIssues: (args: { repoPath: string; limit?: number }): Promise<unknown[]> =>
ipcRenderer.invoke('gh:listIssues', args),
prChecks: (args: { repoPath: string; prNumber: number; branch?: string }): Promise<unknown[]> =>
ipcRenderer.invoke('gh:prChecks', args),
prChecks: (args: {
repoPath: string
prNumber: number
branch?: string
noCache?: boolean
}): Promise<unknown[]> => ipcRenderer.invoke('gh:prChecks', args),
updatePRTitle: (args: {
repoPath: string
+2 -1
View File
@@ -193,7 +193,8 @@ export const createGitHubSlice: StateCreator<AppState, [], [], GitHubSlice> = (s
const checks = (await window.api.gh.prChecks({
repoPath,
prNumber,
branch
branch,
noCache: options?.force
})) as PRCheckDetail[]
set((s) => {
const nextState: Partial<AppState> = {