mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 15:36:25 +00:00
fix(package-rules): add groupSlug to matched package rule if necessary (#10621)
* fix(package-rules): add groupSlug to matched package rule if necessary * Update lib/util/package-rules.spec.ts Co-authored-by: Michael Kriese <michael.kriese@visualon.de> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
parent
3be44469bb
commit
248d7c7719
2 changed files with 28 additions and 1 deletions
|
@ -714,4 +714,23 @@ describe('applyPackageRules()', () => {
|
||||||
applyPackageRules({ ...config1, packageRules: null })
|
applyPackageRules({ ...config1, packageRules: null })
|
||||||
).toMatchSnapshot();
|
).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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import is from '@sindresorhus/is';
|
import is from '@sindresorhus/is';
|
||||||
import minimatch from 'minimatch';
|
import minimatch from 'minimatch';
|
||||||
|
import slugify from 'slugify';
|
||||||
import { mergeChildConfig } from '../config';
|
import { mergeChildConfig } from '../config';
|
||||||
import type { PackageRule, PackageRuleInputConfig } from '../config/types';
|
import type { PackageRule, PackageRuleInputConfig } from '../config/types';
|
||||||
import { logger } from '../logger';
|
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
|
// This rule is considered matched if there was at least one positive match and no negative matches
|
||||||
if (matchesRule(config, packageRule)) {
|
if (matchesRule(config, packageRule)) {
|
||||||
// Package rule config overrides any existing config
|
// 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.matchPackageNames;
|
||||||
delete config.matchPackagePatterns;
|
delete config.matchPackagePatterns;
|
||||||
delete config.matchPackagePrefixes;
|
delete config.matchPackagePrefixes;
|
||||||
|
|
Loading…
Reference in a new issue