Compare commits

...

2 Commits

Author SHA1 Message Date
Colin McDonnell dc93c89c24 0.0.136 2025-12-15 19:10:24 -08:00
Colin McDonnell b7511752b6 Improve PR review on external PRs 2025-12-15 19:10:10 -08:00
4 changed files with 69 additions and 15 deletions
+27 -5
View File
@@ -97443,7 +97443,7 @@ function query({
// package.json // package.json
var package_default = { var package_default = {
name: "@pullfrog/action", name: "@pullfrog/action",
version: "0.0.135", version: "0.0.136",
type: "module", type: "module",
files: [ files: [
"index.js", "index.js",
@@ -124808,10 +124808,10 @@ var PullRequestInfoTool = tool({
} }
log.info(`Fetching base branch: origin/${baseBranch}`); log.info(`Fetching base branch: origin/${baseBranch}`);
$("git", ["fetch", "origin", baseBranch, "--depth=20"]); $("git", ["fetch", "origin", baseBranch, "--depth=20"]);
log.info(`Fetching PR branch: origin/${headBranch}`); log.info(`Fetching PR #${pull_number} using refs/pull/${pull_number}/head`);
$("git", ["fetch", "origin", headBranch]); $("git", ["fetch", "origin", `refs/pull/${pull_number}/head`]);
log.info(`Checking out PR branch: origin/${headBranch}`); log.info(`Checking out PR branch: ${headBranch}`);
$("git", ["checkout", "-B", headBranch, `origin/${headBranch}`]); $("git", ["checkout", "-B", headBranch, "FETCH_HEAD"]);
return { return {
number: data.number, number: data.number,
url: data.html_url, url: data.html_url,
@@ -125202,6 +125202,28 @@ function setupGitBranch(payload) {
return; return;
} }
log.info(`\u{1F33F} Setting up git branch: ${branch}`); log.info(`\u{1F33F} Setting up git branch: ${branch}`);
const issueNumber = "issue_number" in payload.event ? payload.event.issue_number : void 0;
const isLikelyPR = issueNumber !== void 0 && branch !== void 0;
if (isLikelyPR) {
try {
log.debug(`Fetching PR #${issueNumber} using refs/pull/${issueNumber}/head`);
execSync(`git fetch origin refs/pull/${issueNumber}/head`, {
cwd: repoDir,
stdio: "pipe"
});
log.debug(`Checking out branch: ${branch}`);
execSync(`git checkout -B ${branch} FETCH_HEAD`, {
cwd: repoDir,
stdio: "pipe"
});
log.info(`\u2713 Successfully checked out PR branch: ${branch}`);
return;
} catch (error41) {
log.debug(
`PR ref fetch failed, falling back to branch name fetch: ${error41 instanceof Error ? error41.message : String(error41)}`
);
}
}
try { try {
log.debug(`Fetching branch from origin: ${branch}`); log.debug(`Fetching branch from origin: ${branch}`);
execSync(`git fetch origin ${branch}`, { execSync(`git fetch origin ${branch}`, {
+7 -5
View File
@@ -32,12 +32,14 @@ export const PullRequestInfoTool = tool({
log.info(`Fetching base branch: origin/${baseBranch}`); log.info(`Fetching base branch: origin/${baseBranch}`);
$("git", ["fetch", "origin", baseBranch, "--depth=20"]); $("git", ["fetch", "origin", baseBranch, "--depth=20"]);
log.info(`Fetching PR branch: origin/${headBranch}`); // use GitHub's PR ref which works for both fork and non-fork PRs
$("git", ["fetch", "origin", headBranch]); // refs/pull/{number}/head always points to the PR head commit
log.info(`Fetching PR #${pull_number} using refs/pull/${pull_number}/head`);
$("git", ["fetch", "origin", `refs/pull/${pull_number}/head`]);
log.info(`Checking out PR branch: origin/${headBranch}`); log.info(`Checking out PR branch: ${headBranch}`);
// check out a local branch tracking the remote branch so we can push changes // check out a local branch from FETCH_HEAD (the PR ref we just fetched)
$("git", ["checkout", "-B", headBranch, `origin/${headBranch}`]); $("git", ["checkout", "-B", headBranch, "FETCH_HEAD"]);
return { return {
number: data.number, number: data.number,
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@pullfrog/action", "name": "@pullfrog/action",
"version": "0.0.135", "version": "0.0.136",
"type": "module", "type": "module",
"files": [ "files": [
"index.js", "index.js",
+34 -4
View File
@@ -109,15 +109,45 @@ export function setupGitBranch(payload: Payload): void {
log.info(`🌿 Setting up git branch: ${branch}`); log.info(`🌿 Setting up git branch: ${branch}`);
// if event has issue_number and branch, it's likely a PR - try PR ref first (works for forks)
const issueNumber = "issue_number" in payload.event ? payload.event.issue_number : undefined;
const isLikelyPR = issueNumber !== undefined && branch !== undefined;
if (isLikelyPR) {
try {
// use GitHub's PR ref which works for both fork and non-fork PRs
log.debug(`Fetching PR #${issueNumber} using refs/pull/${issueNumber}/head`);
execSync(`git fetch origin refs/pull/${issueNumber}/head`, {
cwd: repoDir,
stdio: "pipe",
});
// checkout from FETCH_HEAD (the PR ref we just fetched)
log.debug(`Checking out branch: ${branch}`);
execSync(`git checkout -B ${branch} FETCH_HEAD`, {
cwd: repoDir,
stdio: "pipe",
});
log.info(`✓ Successfully checked out PR branch: ${branch}`);
return;
} catch (error) {
// if PR ref fetch fails, fall back to branch name fetch
log.debug(
`PR ref fetch failed, falling back to branch name fetch: ${error instanceof Error ? error.message : String(error)}`
);
}
}
// fallback: fetch by branch name (for non-PR contexts or if PR ref fetch failed)
try { try {
// Fetch the branch from origin
log.debug(`Fetching branch from origin: ${branch}`); log.debug(`Fetching branch from origin: ${branch}`);
execSync(`git fetch origin ${branch}`, { execSync(`git fetch origin ${branch}`, {
cwd: repoDir, cwd: repoDir,
stdio: "pipe", stdio: "pipe",
}); });
// Checkout the branch, creating local tracking branch // checkout the branch, creating local tracking branch
log.debug(`Checking out branch: ${branch}`); log.debug(`Checking out branch: ${branch}`);
execSync(`git checkout -B ${branch} origin/${branch}`, { execSync(`git checkout -B ${branch} origin/${branch}`, {
cwd: repoDir, cwd: repoDir,
@@ -126,8 +156,8 @@ export function setupGitBranch(payload: Payload): void {
log.info(`✓ Successfully checked out branch: ${branch}`); log.info(`✓ Successfully checked out branch: ${branch}`);
} catch (error) { } catch (error) {
// If git operations fail, log warning but don't fail the action // if git operations fail, log warning but don't fail the action
// The agent might still be able to work with the default branch // the agent might still be able to work with the default branch
log.warning( log.warning(
`Failed to checkout branch ${branch}: ${error instanceof Error ? error.message : String(error)}` `Failed to checkout branch ${branch}: ${error instanceof Error ? error.message : String(error)}`
); );