Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: branchPrefixOld #15591

Merged
7 changes: 7 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 313,13 @@ e.g. instead of `renovate/{{parentDir}}-`, configure the template part in `addit
This setting does not change the default _onboarding_ branch name, i.e. `renovate/configure`.
If you wish to change that too, you need to also configure the field `onboardingBranch` in your global bot config.

## branchPrefixOld
Gabriel-Ladzaretti marked this conversation as resolved.
Show resolved Hide resolved

Renovate checks branch names to see if an update PR was created before.
If you closed a PR, it is ignored and won't be recreated.
Use this option to ignore PR created with `branchPrefixOld`.
Best used with the `branchPrefix` setting.

## branchTopic

This field is combined with `branchPrefix` and `additionalBranchPrefix` to form the full `branchName`. `branchName` uniqueness is important for dependency update grouping or non-grouping so be cautious about ever editing this field manually.
Expand Down
7 changes: 7 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 1214,13 @@ const options: RenovateOptions[] = [
type: 'string',
default: `renovate/`,
},
{
name: 'branchPrefixOld',
description: 'Old Prefix to check for existing PRs.',
stage: 'branch',
type: 'string',
default: `renovate/`,
rarkins marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: 'bumpVersion',
description: 'Bump the version in the package file being updated.',
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,7 @@ export interface RenovateSharedConfig {
automergeStrategy?: MergeStrategy;
pruneBranchAfterAutomerge?: boolean;
branchPrefix?: string;
branchPrefixOld?: string;
branchName?: string;
manager?: string | null;
commitMessage?: string;
Expand Down
19 changes: 19 additions & 0 deletions lib/workers/repository/update/branch/check-existing.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 1,6 @@
import { defaultConfig, partial, platform } from '../../../../../test/util';
import { logger } from '../../../../logger';
import type { Pr } from '../../../../modules/platform';
import { PrState } from '../../../../types';
import type { BranchConfig } from '../../../types';
import { prAlreadyExisted } from './check-existing';
Expand Down Expand Up @@ -37,5 39,22 @@ describe('workers/repository/update/branch/check-existing', () => {
expect(await prAlreadyExisted(config)).toEqual({ number: 12 });
expect(platform.findPr).toHaveBeenCalledTimes(1);
});

it('returns true if second check hits', async () => {
config.branchPrefixOld = 'deps/';
platform.findPr.mockResolvedValueOnce(null);
platform.findPr.mockResolvedValueOnce(partial<Pr>({ number: 12 }));
platform.getPr.mockResolvedValueOnce(
partial<Pr>({
number: 12,
state: PrState.Closed,
})
);
expect(await prAlreadyExisted(config)).toEqual({ number: 12 });
expect(platform.findPr).toHaveBeenCalledTimes(2);
expect(logger.debug).toHaveBeenCalledWith(
`Found closed PR with current title`
);
});
});
});
14 changes: 13 additions & 1 deletion lib/workers/repository/update/branch/check-existing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 14,23 @@ export async function prAlreadyExisted(
}
logger.debug('recreateClosed is false');
// Return if same PR already existed
const pr = await platform.findPr({
let pr = await platform.findPr({
branchName: config.branchName,
prTitle: config.prTitle,
state: PrState.NotOpen,
});

if (!pr && config.branchPrefix !== config.branchPrefixOld) {
pr = await platform.findPr({
branchName: config.branchName.replace(
config.branchPrefix,
config.branchPrefixOld
),
prTitle: config.prTitle,
state: PrState.NotOpen,
});
rarkins marked this conversation as resolved.
Show resolved Hide resolved
}

if (pr) {
logger.debug('Found closed PR with current title');
const prDetails = await platform.getPr(pr.number);
Expand Down