mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
fix(package-rules): migrate matchers with string values (#31083)
This commit is contained in:
parent
0bc5cc1b8c
commit
ded9a7b007
3 changed files with 80 additions and 23 deletions
|
@ -191,6 +191,7 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates config 1`
|
|||
"groupName": "angular packages",
|
||||
"matchPackageNames": [
|
||||
"/^(@angular|typescript)/",
|
||||
"!foo",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
@ -174,6 +174,51 @@ describe('config/migrations/custom/package-rules-migration', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('should migrate all match/exclude when value is of type string', () => {
|
||||
expect(PackageRulesMigration).toMigrate(
|
||||
{
|
||||
packageRules: [
|
||||
{
|
||||
matchPackagePatterns: 'pattern',
|
||||
matchPackagePrefixes: 'prefix1',
|
||||
matchSourceUrlPrefixes: 'prefix1',
|
||||
excludePackageNames: 'excluded',
|
||||
excludePackagePatterns: 'excludepattern',
|
||||
excludePackagePrefixes: 'prefix1b',
|
||||
matchDepPatterns: 'pattern',
|
||||
matchDepPrefixes: 'prefix1',
|
||||
excludeDepNames: 'excluded',
|
||||
excludeDepPatterns: 'excludepattern',
|
||||
excludeDepPrefixes: 'prefix1b',
|
||||
automerge: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
packageRules: [
|
||||
{
|
||||
matchPackageNames: [
|
||||
'/pattern/',
|
||||
'prefix1{/,}**',
|
||||
'!excluded',
|
||||
'!/excludepattern/',
|
||||
'!prefix1b{/,}**',
|
||||
],
|
||||
matchDepNames: [
|
||||
'/pattern/',
|
||||
'prefix1{/,}**',
|
||||
'!excluded',
|
||||
'!/excludepattern/',
|
||||
'!prefix1b{/,}**',
|
||||
],
|
||||
matchSourceUrls: ['prefix1{/,}**'],
|
||||
automerge: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('should migrate all match/exclude at once', () => {
|
||||
expect(PackageRulesMigration).toMigrate(
|
||||
{
|
||||
|
|
|
@ -30,52 +30,57 @@ function renameKeys(packageRule: PackageRule): PackageRule {
|
|||
function mergeMatchers(packageRule: PackageRule): PackageRule {
|
||||
const newPackageRule: PackageRule = { ...packageRule };
|
||||
for (const [key, val] of Object.entries(packageRule)) {
|
||||
const patterns = is.string(val) ? [val] : val;
|
||||
|
||||
// depName
|
||||
if (key === 'matchDepPrefixes') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchDepNames ??= [];
|
||||
newPackageRule.matchDepNames.push(...val.map((v) => `${v}{/,}**`));
|
||||
newPackageRule.matchDepNames.push(...patterns.map((v) => `${v}{/,}**`));
|
||||
}
|
||||
delete newPackageRule.matchDepPrefixes;
|
||||
}
|
||||
if (key === 'matchDepPatterns') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchDepNames ??= [];
|
||||
newPackageRule.matchDepNames.push(...val.map((v) => `/${v}/`));
|
||||
newPackageRule.matchDepNames.push(...patterns.map((v) => `/${v}/`));
|
||||
}
|
||||
delete newPackageRule.matchDepPatterns;
|
||||
}
|
||||
if (key === 'excludeDepNames') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchDepNames ??= [];
|
||||
newPackageRule.matchDepNames.push(...val.map((v) => `!${v}`));
|
||||
newPackageRule.matchDepNames.push(...patterns.map((v) => `!${v}`));
|
||||
}
|
||||
delete newPackageRule.excludeDepNames;
|
||||
}
|
||||
if (key === 'excludeDepPrefixes') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchDepNames ??= [];
|
||||
newPackageRule.matchDepNames.push(...val.map((v) => `!${v}{/,}**`));
|
||||
newPackageRule.matchDepNames.push(
|
||||
...patterns.map((v) => `!${v}{/,}**`),
|
||||
);
|
||||
}
|
||||
delete newPackageRule.excludeDepPrefixes;
|
||||
}
|
||||
if (key === 'excludeDepPatterns') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchDepNames ??= [];
|
||||
newPackageRule.matchDepNames.push(...val.map((v) => `!/${v}/`));
|
||||
newPackageRule.matchDepNames.push(...patterns.map((v) => `!/${v}/`));
|
||||
}
|
||||
delete newPackageRule.excludeDepPatterns;
|
||||
}
|
||||
// packageName
|
||||
if (key === 'matchPackagePrefixes') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchPackageNames ??= [];
|
||||
newPackageRule.matchPackageNames.push(...val.map((v) => `${v}{/,}**`));
|
||||
newPackageRule.matchPackageNames.push(
|
||||
...patterns.map((v) => `${v}{/,}**`),
|
||||
);
|
||||
}
|
||||
delete newPackageRule.matchPackagePrefixes;
|
||||
}
|
||||
if (key === 'matchPackagePatterns') {
|
||||
const patterns = is.string(val) ? [val] : val;
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchPackageNames ??= [];
|
||||
newPackageRule.matchPackageNames.push(
|
||||
|
@ -90,39 +95,45 @@ function mergeMatchers(packageRule: PackageRule): PackageRule {
|
|||
delete newPackageRule.matchPackagePatterns;
|
||||
}
|
||||
if (key === 'excludePackageNames') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchPackageNames ??= [];
|
||||
newPackageRule.matchPackageNames.push(...val.map((v) => `!${v}`));
|
||||
newPackageRule.matchPackageNames.push(...patterns.map((v) => `!${v}`));
|
||||
}
|
||||
delete newPackageRule.excludePackageNames;
|
||||
}
|
||||
if (key === 'excludePackagePrefixes') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchPackageNames ??= [];
|
||||
newPackageRule.matchPackageNames.push(...val.map((v) => `!${v}{/,}**`));
|
||||
newPackageRule.matchPackageNames.push(
|
||||
...patterns.map((v) => `!${v}{/,}**`),
|
||||
);
|
||||
}
|
||||
delete newPackageRule.excludePackagePrefixes;
|
||||
}
|
||||
if (key === 'excludePackagePatterns') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchPackageNames ??= [];
|
||||
newPackageRule.matchPackageNames.push(...val.map((v) => `!/${v}/`));
|
||||
newPackageRule.matchPackageNames.push(
|
||||
...patterns.map((v) => `!/${v}/`),
|
||||
);
|
||||
}
|
||||
delete newPackageRule.excludePackagePatterns;
|
||||
}
|
||||
// sourceUrl
|
||||
if (key === 'matchSourceUrlPrefixes') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchSourceUrls ??= [];
|
||||
newPackageRule.matchSourceUrls.push(...val.map((v) => `${v}{/,}**`));
|
||||
newPackageRule.matchSourceUrls.push(
|
||||
...patterns.map((v) => `${v}{/,}**`),
|
||||
);
|
||||
}
|
||||
delete newPackageRule.matchSourceUrlPrefixes;
|
||||
}
|
||||
// repository
|
||||
if (key === 'excludeRepositories') {
|
||||
if (is.array(val, is.string)) {
|
||||
if (is.array(patterns, is.string)) {
|
||||
newPackageRule.matchRepositories ??= [];
|
||||
newPackageRule.matchRepositories.push(...val.map((v) => `!${v}`));
|
||||
newPackageRule.matchRepositories.push(...patterns.map((v) => `!${v}`));
|
||||
}
|
||||
delete newPackageRule.excludeRepositories;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue