diff --git a/lib/util/package-rules.spec.ts b/lib/util/package-rules.spec.ts index 5bd2d52ae0656bfc28a89f6a27f98306546cccc3..a4774a46842f06839bb11f62ec03d94e3a76bee7 100644 --- a/lib/util/package-rules.spec.ts +++ b/lib/util/package-rules.spec.ts @@ -714,4 +714,23 @@ describe('applyPackageRules()', () => { applyPackageRules({ ...config1, packageRules: null }) ).toMatchSnapshot(); }); + + it('creates groupSlug if necessary', () => { + const config: TestConfig = { + depName: 'foo', + packageRules: [ + { + matchPackagePatterns: ['*'], + groupName: 'A', + groupSlug: 'a', + }, + { + matchPackagePatterns: ['*'], + groupName: 'B', + }, + ], + }; + const res = applyPackageRules(config); + expect(res.groupSlug).toEqual('b'); + }); }); diff --git a/lib/util/package-rules.ts b/lib/util/package-rules.ts index 413e9df0f3190ea9144cb316ed8b008e69f4d5f2..1fa29033778434b7b950f1340569a6252dae4f01 100644 --- a/lib/util/package-rules.ts +++ b/lib/util/package-rules.ts @@ -1,5 +1,6 @@ import is from '@sindresorhus/is'; import minimatch from 'minimatch'; +import slugify from 'slugify'; import { mergeChildConfig } from '../config'; import type { PackageRule, PackageRuleInputConfig } from '../config/types'; import { logger } from '../logger'; @@ -262,7 +263,14 @@ export function applyPackageRules<T extends PackageRuleInputConfig>( // This rule is considered matched if there was at least one positive match and no negative matches if (matchesRule(config, packageRule)) { // Package rule config overrides any existing config - config = mergeChildConfig(config, packageRule); + const toApply = { ...packageRule }; + if (config.groupSlug && packageRule.groupName && !packageRule.groupSlug) { + // Need to apply groupSlug otherwise the existing one will take precedence + toApply.groupSlug = slugify(packageRule.groupName, { + lower: true, + }); + } + config = mergeChildConfig(config, toApply); delete config.matchPackageNames; delete config.matchPackagePatterns; delete config.matchPackagePrefixes;