Skip to content

Commit

Permalink
fix: remove rebase label (#22293)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 18, 2023
1 parent fc5ddaa commit bcdf843
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 68 deletions.
39 changes: 35 additions & 4 deletions lib/workers/repository/update/branch/index.ts
Expand Up @@ -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<boolean> {
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<void> {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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`);
Expand Down
34 changes: 0 additions & 34 deletions lib/workers/repository/update/branch/reuse.spec.ts
Expand Up @@ -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);
Expand Down
30 changes: 0 additions & 30 deletions 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';
Expand All @@ -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' &&
Expand Down

0 comments on commit bcdf843

Please sign in to comment.