Clean up fork setup
This commit is contained in:
@@ -83327,7 +83327,7 @@ function query({
|
||||
// package.json
|
||||
var package_default = {
|
||||
name: "@pullfrog/action",
|
||||
version: "0.0.143",
|
||||
version: "0.0.144",
|
||||
type: "module",
|
||||
files: [
|
||||
"index.js",
|
||||
@@ -123871,39 +123871,34 @@ async function setupGit(ctx) {
|
||||
} catch {
|
||||
log.debug("No existing authentication headers to remove");
|
||||
}
|
||||
const originUrl = `https://x-access-token:${ctx.githubInstallationToken}@github.com/${ctx.owner}/${ctx.name}.git`;
|
||||
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
||||
log.info("\u2713 Updated origin URL with authentication token");
|
||||
if (ctx.payload.event.is_pr !== true || !ctx.payload.event.issue_number) {
|
||||
log.debug("Not a PR event, staying on default branch");
|
||||
const originUrl = `https://x-access-token:${ctx.githubInstallationToken}@github.com/${ctx.owner}/${ctx.name}.git`;
|
||||
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
||||
log.info("\u2713 Updated origin URL with authentication token");
|
||||
return { pushRemote: "origin" };
|
||||
}
|
||||
const prNumber = ctx.payload.event.issue_number;
|
||||
log.info(`\u{1F33F} Checking out PR #${prNumber}...`);
|
||||
$("gh", ["pr", "checkout", prNumber.toString()], {
|
||||
cwd: repoDir,
|
||||
env: { GH_TOKEN: ctx.githubInstallationToken }
|
||||
});
|
||||
log.info(`\u2713 Successfully checked out PR #${prNumber}`);
|
||||
const pr = await ctx.octokit.rest.pulls.get({
|
||||
owner: ctx.owner,
|
||||
repo: ctx.name,
|
||||
pull_number: prNumber
|
||||
});
|
||||
const headRepo = pr.data.head.repo;
|
||||
const baseRepo = pr.data.base.repo;
|
||||
if (!headRepo || headRepo.full_name === baseRepo.full_name) {
|
||||
return { pushRemote: "origin" };
|
||||
}
|
||||
if (!pr.data.maintainer_can_modify) {
|
||||
log.warning(
|
||||
`\u26A0\uFE0F Fork PR from ${headRepo.owner.login} does not allow maintainer edits. Push may fail.`
|
||||
);
|
||||
if (!headRepo) {
|
||||
throw new Error(`PR #${prNumber} source repository was deleted`);
|
||||
}
|
||||
const branch = pr.data.head.ref;
|
||||
log.info(`\u{1F33F} Checking out PR #${prNumber} (${branch})...`);
|
||||
$("git", ["fetch", "origin", `pull/${prNumber}/head:${branch}`], { cwd: repoDir });
|
||||
$("git", ["checkout", branch], { cwd: repoDir });
|
||||
log.info(`\u2713 Successfully checked out PR #${prNumber}`);
|
||||
const token = process.env.GITHUB_TOKEN || ctx.githubInstallationToken;
|
||||
const forkUrl = `https://x-access-token:${token}@github.com/${headRepo.full_name}.git`;
|
||||
log.info(`\u{1F374} Fork PR detected, will push to: ${headRepo.full_name}`);
|
||||
return { pushRemote: forkUrl };
|
||||
const pushUrl = `https://x-access-token:${token}@github.com/${headRepo.full_name}.git`;
|
||||
const isFork = headRepo.full_name !== pr.data.base.repo.full_name;
|
||||
if (isFork) {
|
||||
log.info(`\u{1F374} Fork PR detected, will push to: ${headRepo.full_name}`);
|
||||
}
|
||||
return { pushRemote: pushUrl };
|
||||
}
|
||||
|
||||
// utils/timer.ts
|
||||
|
||||
Reference in New Issue
Block a user