Clean up pr naming
This commit is contained in:
@@ -130031,17 +130031,18 @@ async function checkoutPrBranch(params) {
|
||||
const isFork = headRepo.full_name !== pr.data.base.repo.full_name;
|
||||
const baseBranch = pr.data.base.ref;
|
||||
const headBranch = pr.data.head.ref;
|
||||
const currentBranch = $("git", ["rev-parse", "--abbrev-ref", "HEAD"], { log: false }).trim();
|
||||
const alreadyOnBranch = currentBranch === headBranch;
|
||||
const localBranch = `pr-${pullNumber}`;
|
||||
const currentSha = $("git", ["rev-parse", "HEAD"], { log: false }).trim();
|
||||
const alreadyOnBranch = currentSha === pr.data.head.sha;
|
||||
if (alreadyOnBranch) {
|
||||
log.debug(`already on PR branch ${headBranch}, skipping checkout`);
|
||||
log.debug(`already on PR branch ${localBranch}, skipping checkout`);
|
||||
} else {
|
||||
log.debug(`\u{1F4E5} fetching base branch (${baseBranch})...`);
|
||||
$("git", ["fetch", "--no-tags", "origin", baseBranch]);
|
||||
$("git", ["checkout", "-B", baseBranch, `origin/${baseBranch}`]);
|
||||
log.debug(`\u{1F33F} fetching PR #${pullNumber} (${headBranch})...`);
|
||||
$("git", ["fetch", "--no-tags", "origin", `pull/${pullNumber}/head:${headBranch}`]);
|
||||
$("git", ["checkout", headBranch]);
|
||||
log.debug(`\u{1F33F} fetching PR #${pullNumber} (${localBranch})...`);
|
||||
$("git", ["fetch", "--no-tags", "origin", `pull/${pullNumber}/head:${localBranch}`]);
|
||||
$("git", ["checkout", localBranch]);
|
||||
log.debug(`\u2713 checked out PR #${pullNumber}`);
|
||||
}
|
||||
if (alreadyOnBranch) {
|
||||
@@ -130058,15 +130059,17 @@ async function checkoutPrBranch(params) {
|
||||
$("git", ["remote", "set-url", remoteName, forkUrl]);
|
||||
log.debug(`\u{1F4CC} updated remote '${remoteName}' for fork ${headRepo.full_name}`);
|
||||
}
|
||||
$("git", ["config", `branch.${headBranch}.pushRemote`, remoteName]);
|
||||
log.debug(`\u{1F4CC} configured branch '${headBranch}' to push to '${remoteName}'`);
|
||||
$("git", ["config", `branch.${localBranch}.pushRemote`, remoteName]);
|
||||
$("git", ["config", `branch.${localBranch}.merge`, `refs/heads/${headBranch}`]);
|
||||
log.debug(`\u{1F4CC} configured branch '${localBranch}' to push to '${remoteName}/${headBranch}'`);
|
||||
if (!pr.data.maintainer_can_modify) {
|
||||
log.warning(
|
||||
`\u26A0\uFE0F fork PR has maintainer_can_modify=false - push operations will fail. ask the PR author to enable "Allow edits from maintainers" or the fork may be owned by an organization.`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$("git", ["config", `branch.${headBranch}.pushRemote`, "origin"]);
|
||||
$("git", ["config", `branch.${localBranch}.pushRemote`, "origin"]);
|
||||
$("git", ["config", `branch.${localBranch}.merge`, `refs/heads/${headBranch}`]);
|
||||
}
|
||||
return { prNumber: pullNumber };
|
||||
}
|
||||
@@ -131118,8 +131121,15 @@ function PushBranchTool(_ctx) {
|
||||
remote = $("git", ["config", `branch.${branch}.pushRemote`], { log: false }).trim();
|
||||
} catch {
|
||||
}
|
||||
const args3 = force ? ["push", "--force", "-u", remote, branch] : ["push", "-u", remote, branch];
|
||||
log.debug(`pushing branch ${branch} to ${remote}`);
|
||||
let remoteBranch = branch;
|
||||
try {
|
||||
const mergeRef = $("git", ["config", `branch.${branch}.merge`], { log: false }).trim();
|
||||
remoteBranch = mergeRef.replace("refs/heads/", "");
|
||||
} catch {
|
||||
}
|
||||
const refspec = branch === remoteBranch ? branch : `${branch}:${remoteBranch}`;
|
||||
const args3 = force ? ["push", "--force", "-u", remote, refspec] : ["push", "-u", remote, refspec];
|
||||
log.debug(`pushing ${branch} to ${remote}/${remoteBranch}`);
|
||||
if (force) {
|
||||
log.warning(`force pushing - this will overwrite remote history`);
|
||||
}
|
||||
@@ -131127,9 +131137,10 @@ function PushBranchTool(_ctx) {
|
||||
return {
|
||||
success: true,
|
||||
branch,
|
||||
remoteBranch,
|
||||
remote,
|
||||
force,
|
||||
message: `successfully pushed branch ${branch}`
|
||||
message: `successfully pushed ${branch} to ${remote}/${remoteBranch}`
|
||||
};
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user