mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
refactor(rebaseWhen): small refactor for rebaseWhen value setter (#32175)
This commit is contained in:
parent
7527f13520
commit
5028c9056f
1 changed files with 37 additions and 32 deletions
|
@ -37,34 +37,10 @@ export async function shouldReuseExistingBranch(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
logger.debug(`Branch already exists`);
|
logger.debug(`Branch already exists`);
|
||||||
if (result.rebaseWhen === 'auto') {
|
const keepUpdated = await shouldKeepUpdated(result, baseBranch, branchName);
|
||||||
if (result.automerge === true) {
|
await determineRebaseWhenValue(result, keepUpdated);
|
||||||
logger.debug(
|
|
||||||
'Converting rebaseWhen=auto to rebaseWhen=behind-base-branch because automerge=true',
|
if (result.rebaseWhen === 'behind-base-branch' || keepUpdated) {
|
||||||
);
|
|
||||||
result.rebaseWhen = 'behind-base-branch';
|
|
||||||
} else if (await platform.getBranchForceRebase?.(result.baseBranch)) {
|
|
||||||
logger.debug(
|
|
||||||
'Converting rebaseWhen=auto to rebaseWhen=behind-base-branch because platform is configured to require up-to-date branches',
|
|
||||||
);
|
|
||||||
result.rebaseWhen = 'behind-base-branch';
|
|
||||||
} else if (await shouldKeepUpdated(result, baseBranch, branchName)) {
|
|
||||||
logger.debug(
|
|
||||||
'Converting rebaseWhen=auto to rebaseWhen=behind-base-branch because keep-updated label is set',
|
|
||||||
);
|
|
||||||
result.rebaseWhen = 'behind-base-branch';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result.rebaseWhen === 'auto') {
|
|
||||||
logger.debug(
|
|
||||||
'Converting rebaseWhen=auto to rebaseWhen=conflicted because no rule for converting to rebaseWhen=behind-base-branch applies',
|
|
||||||
);
|
|
||||||
result.rebaseWhen = 'conflicted';
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
result.rebaseWhen === 'behind-base-branch' ||
|
|
||||||
(await shouldKeepUpdated(result, baseBranch, branchName))
|
|
||||||
) {
|
|
||||||
if (await scm.isBranchBehindBase(branchName, baseBranch)) {
|
if (await scm.isBranchBehindBase(branchName, baseBranch)) {
|
||||||
logger.debug(`Branch is behind base branch and needs rebasing`);
|
logger.debug(`Branch is behind base branch and needs rebasing`);
|
||||||
// We can rebase the branch only if no PR or PR can be rebased
|
// We can rebase the branch only if no PR or PR can be rebased
|
||||||
|
@ -91,10 +67,7 @@ export async function shouldReuseExistingBranch(
|
||||||
|
|
||||||
if ((await scm.isBranchModified(branchName, baseBranch)) === false) {
|
if ((await scm.isBranchModified(branchName, baseBranch)) === false) {
|
||||||
logger.debug(`Branch is not mergeable and needs rebasing`);
|
logger.debug(`Branch is not mergeable and needs rebasing`);
|
||||||
if (
|
if (result.rebaseWhen === 'never' && !keepUpdated) {
|
||||||
result.rebaseWhen === 'never' &&
|
|
||||||
!(await shouldKeepUpdated(result, baseBranch, branchName))
|
|
||||||
) {
|
|
||||||
logger.debug('Rebasing disabled by config');
|
logger.debug('Rebasing disabled by config');
|
||||||
result.reuseExistingBranch = true;
|
result.reuseExistingBranch = true;
|
||||||
result.isModified = false;
|
result.isModified = false;
|
||||||
|
@ -136,3 +109,35 @@ export async function shouldReuseExistingBranch(
|
||||||
result.isModified = false;
|
result.isModified = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method updates rebaseWhen value when it's set to auto(default)
|
||||||
|
*
|
||||||
|
* @param result BranchConfig
|
||||||
|
* @param keepUpdated boolean
|
||||||
|
*/
|
||||||
|
async function determineRebaseWhenValue(
|
||||||
|
result: BranchConfig,
|
||||||
|
keepUpdated: boolean,
|
||||||
|
): Promise<void> {
|
||||||
|
if (result.rebaseWhen === 'auto') {
|
||||||
|
let reason;
|
||||||
|
|
||||||
|
let newValue = 'behind-base-branch';
|
||||||
|
if (result.automerge === true) {
|
||||||
|
reason = 'automerge=true';
|
||||||
|
} else if (await platform.getBranchForceRebase?.(result.baseBranch)) {
|
||||||
|
reason = 'platform is configured to require up-to-date branches';
|
||||||
|
} else if (keepUpdated) {
|
||||||
|
reason = 'keep-updated label is set';
|
||||||
|
} else {
|
||||||
|
newValue = 'conflicted';
|
||||||
|
reason = 'no rule for behind-base-branch applies';
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
`Converting rebaseWhen=${result.rebaseWhen} to rebaseWhen=${newValue} because ${reason}`,
|
||||||
|
);
|
||||||
|
result.rebaseWhen = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue