From bcdf8439d61e0358c6c1484c5fc185dd458c9d9b Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Thu, 18 May 2023 12:56:16 +0200 Subject: [PATCH] fix: remove rebase label (#22293) --- lib/workers/repository/update/branch/index.ts | 39 +++++++++++++++++-- .../repository/update/branch/reuse.spec.ts | 34 ---------------- lib/workers/repository/update/branch/reuse.ts | 30 -------------- 3 files changed, 35 insertions(+), 68 deletions(-) diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index 562a08f61539f7..003da47bb0c4ba 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -48,12 +48,43 @@ import { shouldReuseExistingBranch } from './reuse'; import { isScheduledNow } from './schedule'; import { setConfidence, setStability } from './status-checks'; -function rebaseCheck(config: RenovateConfig, branchPr: Pr): boolean { +async function rebaseCheck( + config: RenovateConfig, + branchPr: Pr +): Promise { const titleRebase = branchPr.title?.startsWith('rebase!'); + if (titleRebase) { + logger.debug( + `Manual rebase requested via PR title for #${branchPr.number}` + ); + return true; + } const labelRebase = !!branchPr.labels?.includes(config.rebaseLabel!); + if (labelRebase) { + logger.debug( + `Manual rebase requested via PR labels for #${branchPr.number}` + ); + // istanbul ignore if + if (GlobalConfig.get('dryRun')) { + logger.info( + `DRY-RUN: Would delete label ${config.rebaseLabel!} from #${ + branchPr.number + }` + ); + } else { + await platform.deleteLabel(branchPr.number, config.rebaseLabel!); + } + return true; + } const prRebaseChecked = !!branchPr.bodyStruct?.rebaseRequested; + if (prRebaseChecked) { + logger.debug( + `Manual rebase requested via PR checkbox for #${branchPr.number}` + ); + return true; + } - return titleRebase || labelRebase || prRebaseChecked; + return false; } async function deleteBranchSilently(branchName: string): Promise { @@ -107,7 +138,7 @@ export async function processBranch( config.dependencyDashboardChecks?.[config.branchName]; logger.debug(`dependencyDashboardCheck=${dependencyDashboardCheck!}`); if (branchPr) { - config.rebaseRequested = rebaseCheck(config, branchPr); + config.rebaseRequested = await rebaseCheck(config, branchPr); logger.debug(`PR rebase requested=${config.rebaseRequested}`); } const artifactErrorTopic = emojify(':warning: Artifact update problem'); @@ -375,7 +406,7 @@ export async function processBranch( const userApproveAllPendingPR = !!config.dependencyDashboardAllPending; const userOpenAllRateLimtedPR = !!config.dependencyDashboardAllRateLimited; if (userRebaseRequested) { - logger.debug('Manual rebase requested via Dependency Dashboard'); + logger.debug('User has requested rebase'); config.reuseExistingBranch = false; } else if (dependencyDashboardCheck === 'global-config') { logger.debug(`Manual create/rebase requested via checkedBranches`); diff --git a/lib/workers/repository/update/branch/reuse.spec.ts b/lib/workers/repository/update/branch/reuse.spec.ts index 05d36d7d84da48..48363129adc0c6 100644 --- a/lib/workers/repository/update/branch/reuse.spec.ts +++ b/lib/workers/repository/update/branch/reuse.spec.ts @@ -115,40 +115,6 @@ describe('workers/repository/update/branch/reuse', () => { expect(res.reuseExistingBranch).toBeTrue(); }); - it('returns false if PR title rebase!', async () => { - scm.branchExists.mockResolvedValueOnce(true); - platform.getBranchPr.mockResolvedValueOnce({ - ...pr, - title: 'rebase!Update foo to v4', - }); - const res = await shouldReuseExistingBranch(config); - expect(res.reuseExistingBranch).toBeFalse(); - }); - - it('returns false if PR body check rebase', async () => { - scm.branchExists.mockResolvedValueOnce(true); - platform.getBranchPr.mockResolvedValueOnce({ - ...pr, - title: 'Update foo to v4', - bodyStruct: { - hash: '123', - rebaseRequested: true, - }, - }); - const res = await shouldReuseExistingBranch(config); - expect(res.reuseExistingBranch).toBeFalse(); - }); - - it('returns false if manual rebase by label', async () => { - scm.branchExists.mockResolvedValueOnce(true); - platform.getBranchPr.mockResolvedValueOnce({ - ...pr, - labels: ['rebase'], - }); - const res = await shouldReuseExistingBranch(config); - expect(res.reuseExistingBranch).toBeFalse(); - }); - it('returns false if unmergeable and can rebase', async () => { scm.branchExists.mockResolvedValueOnce(true); scm.isBranchConflicted.mockResolvedValueOnce(true); diff --git a/lib/workers/repository/update/branch/reuse.ts b/lib/workers/repository/update/branch/reuse.ts index d99be494751221..d21ca798979c43 100644 --- a/lib/workers/repository/update/branch/reuse.ts +++ b/lib/workers/repository/update/branch/reuse.ts @@ -1,4 +1,3 @@ -import { GlobalConfig } from '../../../../config/global'; import { logger } from '../../../../logger'; import { platform } from '../../../../modules/platform'; import { scm } from '../../../../modules/platform/scm'; @@ -22,35 +21,6 @@ export async function shouldReuseExistingBranch( return result; } logger.debug(`Branch already exists`); - - // Check for existing PR - const pr = await platform.getBranchPr(branchName); - - if (pr) { - if (pr.title?.startsWith('rebase!')) { - logger.debug(`Manual rebase requested via PR title for #${pr.number}`); - return result; - } - if (pr.bodyStruct?.rebaseRequested) { - logger.debug(`Manual rebase requested via PR checkbox for #${pr.number}`); - return result; - } - if (pr.labels?.includes(config.rebaseLabel!)) { - logger.debug(`Manual rebase requested via PR labels for #${pr.number}`); - // istanbul ignore if - if (GlobalConfig.get('dryRun')) { - logger.info( - `DRY-RUN: Would delete label ${config.rebaseLabel!} from #${ - pr.number - }` - ); - } else { - await platform.deleteLabel(pr.number, config.rebaseLabel!); - } - return result; - } - } - if ( config.rebaseWhen === 'behind-base-branch' || (config.rebaseWhen === 'auto' &&