diff --git a/lib/workers/branch/reuse.ts b/lib/workers/branch/reuse.ts index 00a9a062be7ca2effad4ac5f019db2cca97da788..cd0e3938ea289a562036d1e4b56735685a7c76f8 100644 --- a/lib/workers/branch/reuse.ts +++ b/lib/workers/branch/reuse.ts @@ -8,16 +8,18 @@ import type { BranchConfig } from '../types'; type ParentBranch = { reuseExistingBranch: boolean; isModified?: boolean; + isConflicted?: boolean; }; export async function shouldReuseExistingBranch( config: BranchConfig ): Promise<ParentBranch> { const { branchName } = config; + const result: ParentBranch = { reuseExistingBranch: false }; // Check if branch exists if (!branchExists(branchName)) { logger.debug(`Branch needs creating`); - return { reuseExistingBranch: false }; + return result; } logger.debug(`Branch already exists`); @@ -27,11 +29,11 @@ export async function shouldReuseExistingBranch( if (pr) { if (pr.title?.startsWith('rebase!')) { logger.debug(`Manual rebase requested via PR title for #${pr.number}`); - return { reuseExistingBranch: false }; + return result; } if (pr.body?.includes(`- [x] <!-- rebase-check -->`)) { logger.debug(`Manual rebase requested via PR checkbox for #${pr.number}`); - return { reuseExistingBranch: false }; + return result; } if (pr.labels?.includes(config.rebaseLabel)) { logger.debug(`Manual rebase requested via PR labels for #${pr.number}`); @@ -43,7 +45,7 @@ export async function shouldReuseExistingBranch( } else { await platform.deleteLabel(pr.number, config.rebaseLabel); } - return { reuseExistingBranch: false }; + return result; } } @@ -56,12 +58,13 @@ export async function shouldReuseExistingBranch( logger.debug(`Branch is stale and needs rebasing`); // We can rebase the branch only if no PR or PR can be rebased if (await isBranchModified(branchName)) { - // TODO: Warn here so that it appears in PR body (#9720) logger.debug('Cannot rebase branch as it has been modified'); - return { reuseExistingBranch: true, isModified: true }; + result.reuseExistingBranch = true; + result.isModified = true; + return result; } logger.debug('Branch is unmodified, so can be rebased'); - return { reuseExistingBranch: false }; + return result; } logger.debug('Branch is up-to-date'); } else { @@ -71,17 +74,19 @@ export async function shouldReuseExistingBranch( } // Now check if PR is unmergeable. If so then we also rebase - if (pr?.isConflicted) { + result.isConflicted = !!pr?.isConflicted; + if (result.isConflicted) { logger.debug('PR is conflicted'); if ((await isBranchModified(branchName)) === false) { logger.debug(`Branch is not mergeable and needs rebasing`); if (config.rebaseWhen === 'never') { logger.debug('Rebasing disabled by config'); - return { reuseExistingBranch: true, isModified: false }; + result.reuseExistingBranch = true; + result.isModified = false; } // Setting reuseExistingBranch back to undefined means that we'll use the default branch - return { reuseExistingBranch: false }; + return result; } // Don't do anything different, but warn // TODO: Add warning to PR (#9720) @@ -107,12 +112,13 @@ export async function shouldReuseExistingBranch( logger.debug( `Detected multiple rangeStrategies along with update-lockfile` ); - return { - reuseExistingBranch: false, - isModified: false, - }; + result.reuseExistingBranch = false; + result.isModified = false; + return result; } } - return { reuseExistingBranch: true, isModified: false }; + result.reuseExistingBranch = true; + result.isModified = false; + return result; }