Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/github/api/queries/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const PR_QUERY = `
baseRefName
headRefName
headRefOid
isCrossRepository
createdAt
updatedAt
lastEditedAt
Expand Down
15 changes: 14 additions & 1 deletion src/github/operations/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,20 @@ export async function setupBranch(

// Execute git commands to checkout PR branch (dynamic depth based on PR size)
// Using execFileSync instead of shell template literals for security
execGit(["fetch", "origin", `--depth=${fetchDepth}`, branchName]);
// For fork PRs, the branch doesn't exist on origin - use refs/pull/N/head instead
if (prData.isCrossRepository) {
console.log(
`Fork PR detected, fetching via refs/pull/${entityNumber}/head`,
);
execGit([
"fetch",
"origin",
`--depth=${fetchDepth}`,
`pull/${entityNumber}/head:${branchName}`,
]);
} else {
execGit(["fetch", "origin", `--depth=${fetchDepth}`, branchName]);
}
execGit(["checkout", branchName, "--"]);

console.log(`Successfully checked out PR branch for PR #${entityNumber}`);
Expand Down
1 change: 1 addition & 0 deletions src/github/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type GitHubPullRequest = {
baseRefName: string;
headRefName: string;
headRefOid: string;
isCrossRepository: boolean;
createdAt: string;
updatedAt?: string;
lastEditedAt?: string;
Expand Down
1 change: 1 addition & 0 deletions test/data-formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("formatContext", () => {
baseRefName: "main",
headRefName: "feature/test",
headRefOid: "abc123",
isCrossRepository: false,
createdAt: "2023-01-01T00:00:00Z",
additions: 50,
deletions: 30,
Expand Down