Skip to content

Commit d9fdebe

Browse files
ubuntudroidclaude
andcommitted
fix: apply fork detection to SSH/remote path in git:get-check-runs
The remote (SSH) code path was still using the hardcoded repos/{owner}/{repo} pattern, causing CI checks to fail for fork projects on SSH workspaces. Apply the same fork detection logic: detect parent repo via gh repo view, find the PR by branch name with owner filtering, then use the parent repo for gh pr checks and the gh api check-runs call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e429eff commit d9fdebe

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

src/main/ipc/gitIpc.ts

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,11 +1694,57 @@ current branch '${currentBranch}' ahead of base '${baseRef}'.`,
16941694
if (remoteProject) {
16951695
const connId = remoteProject.sshConnectionId;
16961696
const fields = 'bucket,completedAt,description,event,link,name,startedAt,state,workflow';
1697-
const checksResult = await remoteGitService.execGh(
1698-
connId,
1699-
taskPath,
1700-
`pr checks --json ${fields}`
1701-
);
1697+
1698+
// Detect fork on remote: find PR in parent repo if applicable
1699+
let prRef: string | null = null;
1700+
let remoteParentRepo: string | null = null;
1701+
let remoteChecksApiRepo = 'repos/{owner}/{repo}';
1702+
let remoteHeadRefOidCmd = "pr view --json headRefOid --jq '.headRefOid'";
1703+
try {
1704+
const repoResult = await remoteGitService.execGh(
1705+
connId,
1706+
taskPath,
1707+
'repo view --json owner,parent'
1708+
);
1709+
const repoData = repoResult.stdout.trim() ? JSON.parse(repoResult.stdout.trim()) : null;
1710+
const parentOwner = repoData?.parent?.owner?.login;
1711+
const parentName = repoData?.parent?.name;
1712+
const parentRepo = parentOwner && parentName ? `${parentOwner}/${parentName}` : null;
1713+
if (parentRepo) {
1714+
const branchResult = await remoteGitService.execGit(
1715+
connId,
1716+
taskPath,
1717+
'branch --show-current'
1718+
);
1719+
const currentBranch = branchResult.stdout.trim();
1720+
if (currentBranch) {
1721+
const listResult = await remoteGitService.execGh(
1722+
connId,
1723+
taskPath,
1724+
`pr list --head ${quoteGhArg(currentBranch)} --repo ${quoteGhArg(parentRepo)} --state open --json number,headRefOid,headRepositoryOwner --limit 10`
1725+
);
1726+
const forkOwnerLogin = repoData?.owner?.login;
1727+
const listData = listResult.stdout.trim() ? JSON.parse(listResult.stdout.trim()) : [];
1728+
const matched = forkOwnerLogin
1729+
? listData.find((pr: any) => pr?.headRepositoryOwner?.login === forkOwnerLogin)
1730+
: listData[0];
1731+
if (matched) {
1732+
prRef = String(matched.number);
1733+
remoteParentRepo = parentRepo;
1734+
remoteChecksApiRepo = `repos/${parentRepo}`;
1735+
remoteHeadRefOidCmd = `pr view ${prRef} --repo ${quoteGhArg(parentRepo)} --json headRefOid --jq '.headRefOid'`;
1736+
}
1737+
}
1738+
}
1739+
} catch {
1740+
// Not a fork or detection failed — proceed with default behavior
1741+
}
1742+
1743+
const checksCmd =
1744+
prRef && remoteParentRepo
1745+
? `pr checks ${prRef} --repo ${quoteGhArg(remoteParentRepo)} --json ${fields}`
1746+
: `pr checks --json ${fields}`;
1747+
const checksResult = await remoteGitService.execGh(connId, taskPath, checksCmd);
17021748
if (checksResult.exitCode !== 0) {
17031749
const msg = checksResult.stderr || '';
17041750
if (/no pull requests? found/i.test(msg) || /not found/i.test(msg)) {
@@ -1713,17 +1759,13 @@ current branch '${currentBranch}' ahead of base '${baseRef}'.`,
17131759

17141760
// Fetch html_url from API
17151761
try {
1716-
const shaResult = await remoteGitService.execGh(
1717-
connId,
1718-
taskPath,
1719-
"pr view --json headRefOid --jq '.headRefOid'"
1720-
);
1762+
const shaResult = await remoteGitService.execGh(connId, taskPath, remoteHeadRefOidCmd);
17211763
const sha = shaResult.stdout.trim();
17221764
if (sha) {
17231765
const apiResult = await remoteGitService.execGh(
17241766
connId,
17251767
taskPath,
1726-
`api repos/{owner}/{repo}/commits/${sha}/check-runs --jq '.check_runs | map({name: .name, html_url: .html_url}) | .[]'`
1768+
`api ${remoteChecksApiRepo}/commits/${sha}/check-runs --jq '.check_runs | map({name: .name, html_url: .html_url}) | .[]'`
17271769
);
17281770
const urlMap = new Map<string, string>();
17291771
for (const line of apiResult.stdout.trim().split('\n')) {

0 commit comments

Comments
 (0)