Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc93c89c24 | |||
| b7511752b6 |
@@ -97443,7 +97443,7 @@ function query({
|
||||
// package.json
|
||||
var package_default = {
|
||||
name: "@pullfrog/action",
|
||||
version: "0.0.135",
|
||||
version: "0.0.136",
|
||||
type: "module",
|
||||
files: [
|
||||
"index.js",
|
||||
@@ -124808,10 +124808,10 @@ var PullRequestInfoTool = tool({
|
||||
}
|
||||
log.info(`Fetching base branch: origin/${baseBranch}`);
|
||||
$("git", ["fetch", "origin", baseBranch, "--depth=20"]);
|
||||
log.info(`Fetching PR branch: origin/${headBranch}`);
|
||||
$("git", ["fetch", "origin", headBranch]);
|
||||
log.info(`Checking out PR branch: origin/${headBranch}`);
|
||||
$("git", ["checkout", "-B", headBranch, `origin/${headBranch}`]);
|
||||
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: ${headBranch}`);
|
||||
$("git", ["checkout", "-B", headBranch, "FETCH_HEAD"]);
|
||||
return {
|
||||
number: data.number,
|
||||
url: data.html_url,
|
||||
@@ -125202,6 +125202,28 @@ function setupGitBranch(payload) {
|
||||
return;
|
||||
}
|
||||
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 {
|
||||
log.debug(`Fetching branch from origin: ${branch}`);
|
||||
execSync(`git fetch origin ${branch}`, {
|
||||
|
||||
+7
-5
@@ -32,12 +32,14 @@ export const PullRequestInfoTool = tool({
|
||||
log.info(`Fetching base branch: origin/${baseBranch}`);
|
||||
$("git", ["fetch", "origin", baseBranch, "--depth=20"]);
|
||||
|
||||
log.info(`Fetching PR branch: origin/${headBranch}`);
|
||||
$("git", ["fetch", "origin", headBranch]);
|
||||
// use GitHub's PR ref which works for both fork and non-fork PRs
|
||||
// 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}`);
|
||||
// check out a local branch tracking the remote branch so we can push changes
|
||||
$("git", ["checkout", "-B", headBranch, `origin/${headBranch}`]);
|
||||
log.info(`Checking out PR branch: ${headBranch}`);
|
||||
// check out a local branch from FETCH_HEAD (the PR ref we just fetched)
|
||||
$("git", ["checkout", "-B", headBranch, "FETCH_HEAD"]);
|
||||
|
||||
return {
|
||||
number: data.number,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pullfrog/action",
|
||||
"version": "0.0.135",
|
||||
"version": "0.0.136",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"index.js",
|
||||
|
||||
+34
-4
@@ -109,15 +109,45 @@ export function setupGitBranch(payload: Payload): void {
|
||||
|
||||
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 {
|
||||
// Fetch the branch from origin
|
||||
log.debug(`Fetching branch from origin: ${branch}`);
|
||||
execSync(`git fetch origin ${branch}`, {
|
||||
cwd: repoDir,
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
// Checkout the branch, creating local tracking branch
|
||||
// checkout the branch, creating local tracking branch
|
||||
log.debug(`Checking out branch: ${branch}`);
|
||||
execSync(`git checkout -B ${branch} origin/${branch}`, {
|
||||
cwd: repoDir,
|
||||
@@ -126,8 +156,8 @@ export function setupGitBranch(payload: Payload): void {
|
||||
|
||||
log.info(`✓ Successfully checked out branch: ${branch}`);
|
||||
} catch (error) {
|
||||
// If git operations fail, log warning but don't fail the action
|
||||
// The agent might still be able to work with the default branch
|
||||
// if git operations fail, log warning but don't fail the action
|
||||
// the agent might still be able to work with the default branch
|
||||
log.warning(
|
||||
`Failed to checkout branch ${branch}: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user