Skip to content

Commit e429eff

Browse files
ubuntudroidclaude
andcommitted
fix: filter fork PR lookup by owner to avoid same-branch-name collisions
When multiple forks share the same branch name, gh pr list could return a PR from a different fork owner. Fix by requesting headRepositoryOwner in the JSON fields and matching against the current repo's owner login before selecting the PR, in both git:get-pr-status and git:get-check-runs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a6648b1 commit e429eff

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/main/ipc/gitIpc.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,12 +1430,17 @@ current branch '${currentBranch}' ahead of base '${baseRef}'.`,
14301430
const parentName = repoData?.parent?.name;
14311431
const parentRepo = parentOwner && parentName ? `${parentOwner}/${parentName}` : null;
14321432
if (parentRepo) {
1433-
const forkListCmd = `gh pr list --head ${JSON.stringify(currentBranch)} --repo ${JSON.stringify(parentRepo)} --state open --json ${queryFields.join(',')} --limit 1`;
1433+
const forkOwnerLogin = repoData?.owner?.login;
1434+
const forkFields = [...queryFields, 'headRepositoryOwner'];
1435+
const forkListCmd = `gh pr list --head ${JSON.stringify(currentBranch)} --repo ${JSON.stringify(parentRepo)} --state open --json ${forkFields.join(',')} --limit 10`;
14341436
const { stdout: forkOut } = await execAsync(forkListCmd, { cwd: taskPath });
14351437
const forkJson = (forkOut || '').trim();
14361438
const forkData = forkJson ? JSON.parse(forkJson) : [];
1437-
if (forkData.length > 0) {
1438-
data = forkData[0];
1439+
const match = forkOwnerLogin
1440+
? forkData.find((pr: any) => pr?.headRepositoryOwner?.login === forkOwnerLogin)
1441+
: forkData[0];
1442+
if (match) {
1443+
data = match;
14391444
}
14401445
}
14411446
} catch (forkFallbackErr) {
@@ -1780,15 +1785,19 @@ current branch '${currentBranch}' ahead of base '${baseRef}'.`,
17801785
'--state',
17811786
'open',
17821787
'--json',
1783-
'number,headRefOid',
1788+
'number,headRefOid,headRepositoryOwner',
17841789
'--limit',
1785-
'1',
1790+
'10',
17861791
],
17871792
{ cwd: taskPath }
17881793
);
1794+
const forkOwnerLogin = repoData?.owner?.login;
17891795
const listData = listOut.trim() ? JSON.parse(listOut.trim()) : [];
1790-
if (listData.length > 0) {
1791-
prRef = String(listData[0].number);
1796+
const matched = forkOwnerLogin
1797+
? listData.find((pr: any) => pr?.headRepositoryOwner?.login === forkOwnerLogin)
1798+
: listData[0];
1799+
if (matched) {
1800+
prRef = String(matched.number);
17921801
repoFlag = ['--repo', parentRepo];
17931802
headRefOidArgs = [
17941803
'pr',

0 commit comments

Comments
 (0)