Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2cedce1bc | |||
| e383dd33dd | |||
| b833cdd4af |
@@ -83327,7 +83327,7 @@ function query({
|
|||||||
// package.json
|
// package.json
|
||||||
var package_default = {
|
var package_default = {
|
||||||
name: "@pullfrog/action",
|
name: "@pullfrog/action",
|
||||||
version: "0.0.140",
|
version: "0.0.142",
|
||||||
type: "module",
|
type: "module",
|
||||||
files: [
|
files: [
|
||||||
"index.js",
|
"index.js",
|
||||||
@@ -98180,8 +98180,9 @@ function buildPullfrogFooter(params) {
|
|||||||
parts.push(`Using [${params.agent.displayName}](${params.agent.url})`);
|
parts.push(`Using [${params.agent.displayName}](${params.agent.url})`);
|
||||||
}
|
}
|
||||||
if (params.workflowRun) {
|
if (params.workflowRun) {
|
||||||
const { owner, repo, runId } = params.workflowRun;
|
parts.push(
|
||||||
parts.push(`[View workflow run](https://github.com/${owner}/${repo}/actions/runs/${runId})`);
|
`[View workflow run](https://github.com/${params.workflowRun.owner}/${params.workflowRun.repo}/actions/runs/${params.workflowRun.runId})`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (params.customParts) {
|
if (params.customParts) {
|
||||||
parts.push(...params.customParts);
|
parts.push(...params.customParts);
|
||||||
@@ -123859,9 +123860,8 @@ function setupGitConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function setupGit(ctx) {
|
function setupGit(ctx) {
|
||||||
const { githubInstallationToken: githubInstallationToken2, payload } = ctx;
|
|
||||||
const repoDir = process.cwd();
|
const repoDir = process.cwd();
|
||||||
log.info("\u{1F527} Setting up git configuration...");
|
log.info("\u{1F527} Setting up git authentication...");
|
||||||
try {
|
try {
|
||||||
execSync("git config --local --unset-all http.https://github.com/.extraheader", {
|
execSync("git config --local --unset-all http.https://github.com/.extraheader", {
|
||||||
cwd: repoDir,
|
cwd: repoDir,
|
||||||
@@ -123871,26 +123871,30 @@ function setupGit(ctx) {
|
|||||||
} catch {
|
} catch {
|
||||||
log.debug("No existing authentication headers to remove");
|
log.debug("No existing authentication headers to remove");
|
||||||
}
|
}
|
||||||
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
const originUrl = `https://x-access-token:${ctx.githubInstallationToken}@github.com/${ctx.owner}/${ctx.name}.git`;
|
||||||
$("git", ["config", "--local", "--add", "credential.helper", "!gh auth git-credential"], {
|
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
||||||
cwd: repoDir,
|
log.info("\u2713 Updated origin URL with authentication token");
|
||||||
env: { GH_TOKEN: githubInstallationToken2 }
|
if (ctx.payload.event.is_pr !== true || !ctx.payload.event.issue_number) {
|
||||||
});
|
|
||||||
log.info("\u2713 Configured gh as credential helper");
|
|
||||||
if (payload.event.is_pr !== true || !payload.event.issue_number) {
|
|
||||||
log.debug("Not a PR event, staying on default branch");
|
log.debug("Not a PR event, staying on default branch");
|
||||||
return { pushRemote: "origin" };
|
return { pushRemote: "origin" };
|
||||||
}
|
}
|
||||||
const prNumber = payload.event.issue_number;
|
const prNumber = ctx.payload.event.issue_number;
|
||||||
log.info(`\u{1F33F} Checking out PR #${prNumber}...`);
|
log.info(`\u{1F33F} Checking out PR #${prNumber}...`);
|
||||||
$("gh", ["pr", "checkout", prNumber.toString()], {
|
$("gh", ["pr", "checkout", prNumber.toString()], {
|
||||||
cwd: repoDir,
|
cwd: repoDir,
|
||||||
env: { GH_TOKEN: githubInstallationToken2 }
|
env: { GH_TOKEN: ctx.githubInstallationToken }
|
||||||
});
|
});
|
||||||
log.info(`\u2713 Successfully checked out PR #${prNumber}`);
|
log.info(`\u2713 Successfully checked out PR #${prNumber}`);
|
||||||
const pushRemote = detectPushRemote();
|
const pushRemote = detectPushRemote();
|
||||||
if (pushRemote !== "origin") {
|
if (pushRemote !== "origin") {
|
||||||
log.info(`\u{1F374} Fork PR detected, will push to remote: ${pushRemote}`);
|
log.info(`\u{1F374} Fork PR detected, will push to remote: ${pushRemote}`);
|
||||||
|
const forkUrl = $("git", ["remote", "get-url", pushRemote], { cwd: repoDir, log: false });
|
||||||
|
const authedForkUrl = forkUrl.replace(
|
||||||
|
"https://github.com/",
|
||||||
|
`https://x-access-token:${ctx.githubInstallationToken}@github.com/`
|
||||||
|
);
|
||||||
|
$("git", ["remote", "set-url", pushRemote, authedForkUrl], { cwd: repoDir });
|
||||||
|
log.info(`\u2713 Updated ${pushRemote} URL with authentication token`);
|
||||||
}
|
}
|
||||||
return { pushRemote };
|
return { pushRemote };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { execute, tool } from "./shared.ts";
|
|||||||
|
|
||||||
export function CreateBranchTool(ctx: Context) {
|
export function CreateBranchTool(ctx: Context) {
|
||||||
const defaultBranch = ctx.repo.default_branch || "main";
|
const defaultBranch = ctx.repo.default_branch || "main";
|
||||||
|
|
||||||
const CreateBranch = type({
|
const CreateBranch = type({
|
||||||
branchName: type.string.describe(
|
branchName: type.string.describe(
|
||||||
"The name of the branch to create (e.g., 'pullfrog/123-fix-bug')"
|
"The name of the branch to create (e.g., 'pullfrog/123-fix-bug')"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pullfrog/action",
|
"name": "@pullfrog/action",
|
||||||
"version": "0.0.140",
|
"version": "0.0.142",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": [
|
"files": [
|
||||||
"index.js",
|
"index.js",
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ export function buildPullfrogFooter(params: BuildPullfrogFooterParams): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (params.workflowRun) {
|
if (params.workflowRun) {
|
||||||
const { owner, repo, runId } = params.workflowRun;
|
parts.push(
|
||||||
parts.push(`[View workflow run](https://github.com/${owner}/${repo}/actions/runs/${runId})`);
|
`[View workflow run](https://github.com/${params.workflowRun.owner}/${params.workflowRun.repo}/actions/runs/${params.workflowRun.runId})`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.customParts) {
|
if (params.customParts) {
|
||||||
|
|||||||
+16
-12
@@ -73,10 +73,9 @@ export type SetupGitResult = {
|
|||||||
* Returns the remote to push to (detected from branch tracking after checkout).
|
* Returns the remote to push to (detected from branch tracking after checkout).
|
||||||
*/
|
*/
|
||||||
export function setupGit(ctx: Context): SetupGitResult {
|
export function setupGit(ctx: Context): SetupGitResult {
|
||||||
const { githubInstallationToken, payload } = ctx;
|
|
||||||
const repoDir = process.cwd();
|
const repoDir = process.cwd();
|
||||||
|
|
||||||
log.info("🔧 Setting up git configuration...");
|
log.info("🔧 Setting up git authentication...");
|
||||||
|
|
||||||
// remove existing git auth headers that actions/checkout might have set
|
// remove existing git auth headers that actions/checkout might have set
|
||||||
try {
|
try {
|
||||||
@@ -89,26 +88,23 @@ export function setupGit(ctx: Context): SetupGitResult {
|
|||||||
log.debug("No existing authentication headers to remove");
|
log.debug("No existing authentication headers to remove");
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up gh as credential helper - this makes git use GH_TOKEN for any remote
|
// embed token directly in origin URL - simple and doesn't expose token in env
|
||||||
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
const originUrl = `https://x-access-token:${ctx.githubInstallationToken}@github.com/${ctx.owner}/${ctx.name}.git`;
|
||||||
$("git", ["config", "--local", "--add", "credential.helper", "!gh auth git-credential"], {
|
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
||||||
cwd: repoDir,
|
log.info("✓ Updated origin URL with authentication token");
|
||||||
env: { GH_TOKEN: githubInstallationToken },
|
|
||||||
});
|
|
||||||
log.info("✓ Configured gh as credential helper");
|
|
||||||
|
|
||||||
// non-PR events: stay on default branch, push to origin
|
// non-PR events: stay on default branch, push to origin
|
||||||
if (payload.event.is_pr !== true || !payload.event.issue_number) {
|
if (ctx.payload.event.is_pr !== true || !ctx.payload.event.issue_number) {
|
||||||
log.debug("Not a PR event, staying on default branch");
|
log.debug("Not a PR event, staying on default branch");
|
||||||
return { pushRemote: "origin" };
|
return { pushRemote: "origin" };
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkout PR branch - gh pr checkout handles fork remotes and tracking automatically
|
// checkout PR branch - gh pr checkout handles fork remotes and tracking automatically
|
||||||
const prNumber = payload.event.issue_number;
|
const prNumber = ctx.payload.event.issue_number;
|
||||||
log.info(`🌿 Checking out PR #${prNumber}...`);
|
log.info(`🌿 Checking out PR #${prNumber}...`);
|
||||||
$("gh", ["pr", "checkout", prNumber.toString()], {
|
$("gh", ["pr", "checkout", prNumber.toString()], {
|
||||||
cwd: repoDir,
|
cwd: repoDir,
|
||||||
env: { GH_TOKEN: githubInstallationToken },
|
env: { GH_TOKEN: ctx.githubInstallationToken },
|
||||||
});
|
});
|
||||||
log.info(`✓ Successfully checked out PR #${prNumber}`);
|
log.info(`✓ Successfully checked out PR #${prNumber}`);
|
||||||
|
|
||||||
@@ -116,6 +112,14 @@ export function setupGit(ctx: Context): SetupGitResult {
|
|||||||
const pushRemote = detectPushRemote();
|
const pushRemote = detectPushRemote();
|
||||||
if (pushRemote !== "origin") {
|
if (pushRemote !== "origin") {
|
||||||
log.info(`🍴 Fork PR detected, will push to remote: ${pushRemote}`);
|
log.info(`🍴 Fork PR detected, will push to remote: ${pushRemote}`);
|
||||||
|
// embed token in fork remote URL too
|
||||||
|
const forkUrl = $("git", ["remote", "get-url", pushRemote], { cwd: repoDir, log: false });
|
||||||
|
const authedForkUrl = forkUrl.replace(
|
||||||
|
"https://github.com/",
|
||||||
|
`https://x-access-token:${ctx.githubInstallationToken}@github.com/`
|
||||||
|
);
|
||||||
|
$("git", ["remote", "set-url", pushRemote, authedForkUrl], { cwd: repoDir });
|
||||||
|
log.info(`✓ Updated ${pushRemote} URL with authentication token`);
|
||||||
}
|
}
|
||||||
return { pushRemote };
|
return { pushRemote };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user