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
6 changes: 6 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 313,12 @@ 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 uses branch names as part of its checks to see if an update PR was created previously, and already merged or ignored.
If you change `branchPrefix`, then no previously closed PRs will match, which could lead to Renovate recreating PRs in such cases.
Instead, set the old `branchPrefix` value as `branchPrefixOld` to allow Renovate to look for those branches too, and avoid this happening.

## 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 @@ -1215,6 1215,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 @@ -27,6 27,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`
);
});
});
});
17 changes: 16 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,26 @@ 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 branchPrefixOld');
}
}

if (pr) {
logger.debug('Found closed PR with current title');
const prDetails = await platform.getPr(pr.number);
Expand Down
35 changes: 35 additions & 0 deletions lib/workers/repository/update/branch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@ import {
MANAGER_LOCKFILE_ERROR,
REPOSITORY_CHANGED,
} from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import * as _npmPostExtract from '../../../../modules/manager/npm/post-update';
import type { WriteExistingFilesResult } from '../../../../modules/manager/npm/post-update/types';
import { hashBody } from '../../../../modules/platform/pr-body';
Expand Down Expand Up @@ -1607,5 1608,39 @@ describe('workers/repository/update/branch/index', () => {
).toMatchObject({ result: BranchResult.NoWork });
expect(commit.commitFilesToBranch).not.toHaveBeenCalled();
});

it('does nothing when branchPrefixOld/branch and its pr exists', async () => {
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({
...updatedPackageFiles,
});
npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({
artifactErrors: [],
updatedArtifacts: [],
});
git.branchExists.mockReturnValueOnce(false);
git.branchExists.mockReturnValueOnce(true);
platform.getBranchPr.mockResolvedValueOnce(
partial<Pr>({
sourceBranch: 'old/some-branch',
state: PrState.Open,
})
);
expect(
await branchWorker.processBranch({
...config,
branchName: 'new/some-branch',
branchPrefix: 'new/',
branchPrefixOld: 'old/',
})
).toEqual({
branchExists: true,
prNo: undefined,
result: 'done',
});
expect(logger.debug).toHaveBeenCalledWith('Found existing branch PR');
expect(logger.debug).toHaveBeenCalledWith(
'No package files need updating'
);
});
});
});
15 changes: 14 additions & 1 deletion lib/workers/repository/update/branch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 83,20 @@ export async function processBranch(
let config: BranchConfig = { ...branchConfig };
logger.trace({ config }, 'processBranch()');
await checkoutBranch(config.baseBranch);
const branchExists = gitBranchExists(config.branchName);
let branchExists = gitBranchExists(config.branchName);

if (!branchExists && config.branchPrefix !== config.branchPrefixOld) {
const branchName = config.branchName.replace(
config.branchPrefix,
config.branchPrefixOld
);
branchExists = gitBranchExists(branchName);
if (branchExists) {
config.branchName = branchName;
rarkins marked this conversation as resolved.
Show resolved Hide resolved
logger.debug('Found existing branch with branchPrefixOld');
}
}

let branchPr = await platform.getBranchPr(config.branchName);
logger.debug(`branchExists=${branchExists}`);
const dependencyDashboardCheck =
Expand Down