use compare API to deepen by exact divergence instead of fixed 1000
This commit is contained in:
committed by
pullfrog[bot]
parent
8bac460177
commit
ed91fbb18d
@@ -146647,15 +146647,33 @@ async function checkoutPrBranch(pullNumber, params) {
|
||||
const baseBranch = pr.data.base.ref;
|
||||
const headBranch = pr.data.head.ref;
|
||||
const localBranch = `pr-${pullNumber}`;
|
||||
const isShallow = $("git", ["rev-parse", "--is-shallow-repository"], { log: false }).trim() === "true";
|
||||
let deepenArgs = [];
|
||||
if (isShallow) {
|
||||
let depth = 1e3;
|
||||
try {
|
||||
const comparison = await octokit.rest.repos.compareCommits({
|
||||
owner,
|
||||
repo: name,
|
||||
base: baseBranch,
|
||||
head: `pull/${pullNumber}/head`
|
||||
});
|
||||
depth = comparison.data.behind_by + 10;
|
||||
log.debug(
|
||||
`\xBB PR is ${comparison.data.behind_by} commits behind ${baseBranch}, deepening by ${depth}`
|
||||
);
|
||||
} catch {
|
||||
log.debug(`\xBB compare API failed, falling back to --deepen=${depth}`);
|
||||
}
|
||||
deepenArgs = [`--deepen=${depth}`];
|
||||
}
|
||||
const currentSha = $("git", ["rev-parse", "HEAD"], { log: false }).trim();
|
||||
const alreadyOnBranch = currentSha === pr.data.head.sha;
|
||||
if (alreadyOnBranch) {
|
||||
log.debug(`already on PR branch ${localBranch}, skipping checkout`);
|
||||
} else {
|
||||
log.debug(`\xBB fetching base branch (${baseBranch})...`);
|
||||
const isShallow = $("git", ["rev-parse", "--is-shallow-repository"], { log: false }).trim();
|
||||
const baseFetchArgs = isShallow === "true" ? ["--deepen=1000", "--no-tags", "origin", baseBranch] : ["--no-tags", "origin", baseBranch];
|
||||
$git("fetch", baseFetchArgs, {
|
||||
$git("fetch", [...deepenArgs, "--no-tags", "origin", baseBranch], {
|
||||
token: gitToken,
|
||||
restricted: shell !== "enabled"
|
||||
});
|
||||
@@ -146670,9 +146688,7 @@ async function checkoutPrBranch(pullNumber, params) {
|
||||
}
|
||||
if (alreadyOnBranch) {
|
||||
log.debug(`\xBB fetching base branch (${baseBranch})...`);
|
||||
const isShallow = $("git", ["rev-parse", "--is-shallow-repository"], { log: false }).trim();
|
||||
const baseFetchArgs = isShallow === "true" ? ["--deepen=1000", "--no-tags", "origin", baseBranch] : ["--no-tags", "origin", baseBranch];
|
||||
$git("fetch", baseFetchArgs, {
|
||||
$git("fetch", [...deepenArgs, "--no-tags", "origin", baseBranch], {
|
||||
token: gitToken,
|
||||
restricted: shell !== "enabled"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user