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(package-rules)!: match packageName for matchPackageNames #22703

Merged
merged 25 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1169d19
feat!: allow post upgrade templating by default (#21326)
rarkins Apr 5, 2023
a9f5219
feat(automerge)!: default to platformAutomerge=true (#21327)
rarkins Apr 5, 2023
c1b63f6
feat(platform/gitlab)!: prefer `commit_email` (#21122
viceice Apr 26, 2023
ca7357f
fix(post-upgrade-tasks)!: enable dot option for file filters (#21282)
bgutschke Apr 26, 2023
bbc72d9
feat(npm)!: disable rollbackPrs for npm by default (#21970)
rarkins May 5, 2023
3f432a4
fix(presets)!: remove compatibility:additionalBranchPrefix (#22015)
rarkins May 7, 2023
6e95ba7
feat(package-rules)!: remove fuzzy matchPaths matching (#22394)
rarkins May 24, 2023
107e2bc
feat!: merge matchPaths and matchFiles into matchFileNames (#22406)
rarkins May 25, 2023
8bc9a6a
feat(package-rules)!: match packageName for matchPackageNames
rarkins Jun 12, 2023
fcb67af
feat!: allow post upgrade templating by default (#21326)
rarkins Apr 5, 2023
22ad73c
feat(automerge)!: default to platformAutomerge=true (#21327)
rarkins Apr 5, 2023
9df6457
feat(platform/gitlab)!: prefer `commit_email` (#21122
viceice Apr 26, 2023
c7f0604
fix(post-upgrade-tasks)!: enable dot option for file filters (#21282)
bgutschke Apr 26, 2023
be162f9
feat(npm)!: disable rollbackPrs for npm by default (#21970)
rarkins May 5, 2023
775eb99
fix(presets)!: remove compatibility:additionalBranchPrefix (#22015)
rarkins May 7, 2023
ff724cf
feat(package-rules)!: remove fuzzy matchPaths matching (#22394)
rarkins May 24, 2023
77cf950
feat!: merge matchPaths and matchFiles into matchFileNames (#22406)
rarkins May 25, 2023
136eece
feat!: remove `skipInstalls` config option (#22648)
RahulGautamSingh Jun 12, 2023
1eb2533
feat!: replace `dockerImagePrefix` with `dockerSidecarImage` (#22708)
RahulGautamSingh Jun 17, 2023
93a7751
feat!: Revert "feat!: remove `skipInstalls` config option (#22648)"
rarkins Jun 18, 2023
6515df8
feat(release-notes)!: support configurable fetching stage (#22781)
RahulGautamSingh Jun 18, 2023
553d2bc
Merge branch 'v36' into feat/20926-match-package-names
rarkins Jun 18, 2023
1eb534e
Merge branch 'v36' into feat/20926-match-package-names
rarkins Jun 18, 2023
e094aec
simplify
rarkins Jun 24, 2023
10850d1
Merge branch 'v36' into feat/20926-match-package-names
rarkins Jun 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions docs/usage/self-hosted-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ Source: [AWS S3 documentation - Interface BucketEndpointInputConfig](https://doc

If set, Renovate will terminate the whole process group of a terminated child process spawned by Renovate.

## `RENOVATE_X_MATCH_PACKAGE_NAMES_MORE`

If set, you'll get the following behavior.

When using `matchPackageNames` and `matchPackagePatterns` matchers:

1. Renovate first tries to match against `depName`
2. If `depName` doesn't match then Renovate tries to match against `packageName`

## `RENOVATE_X_MERGE_CONFIDENCE_API_BASE_URL`

If set, Renovate will query this API for Merge Confidence data.
Expand Down
41 changes: 0 additions & 41 deletions lib/util/package-rules/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,45 +1210,4 @@ describe('util/package-rules/index', () => {
expect(res1.x).toBeUndefined();
expect(res2.x).toBe(1);
});

describe('test matchers supporting RENOVATE_X_MATCH_PACKAGE_NAMES_MORE', () => {
const processEnvOrg: NodeJS.ProcessEnv = process.env;

afterEach(() => {
process.env = processEnvOrg;
});

it.each`
matcherName | isXEnvEnabled | expected
${'matchPackageNames'} | ${false} | ${undefined}
${'matchPackagePatterns'} | ${false} | ${undefined}
${'matchPackageNames'} | ${true} | ${1}
${'matchPackagePatterns'} | ${true} | ${1}
`(
'tests $matcherName selector when experimental env is $isXEnvEnabled (expected res=$expected)',
({ matcherName, isXEnvEnabled, expected }) => {
if (isXEnvEnabled) {
process.env.RENOVATE_X_MATCH_PACKAGE_NAMES_MORE = 'true';
}
const config: TestConfig = {
packageRules: [
{
[matcherName]: ['does-match'],
x: 1,
},
],
};

const res = applyPackageRules({
...config,
depName: 'does-not-match',
packageName: 'does-match',
});

applyPackageRules(config); // coverage

expect(res.x).toBe(expected);
}
);
});
});
26 changes: 26 additions & 0 deletions lib/util/package-rules/package-names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ describe('util/package-rules/package-names', () => {
);
expect(result).toBeFalse();
});

it('should matchPackageName', () => {
const result = packageNameMatcher.matches(
{
depName: 'abc',
packageName: 'def',
},
{
matchPackageNames: ['def'],
}
);
expect(result).toBeTrue();
});

it('should fall back to matching depName', () => {
const result = packageNameMatcher.matches(
{
depName: 'abc',
packageName: 'def',
},
{
matchPackageNames: ['abc'],
}
);
expect(result).toBeTrue();
});
});

describe('exclude', () => {
Expand Down
14 changes: 8 additions & 6 deletions lib/util/package-rules/package-names.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import is from '@sindresorhus/is';
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
import { logger } from '../../logger';
import { Matcher } from './base';

export class PackageNameMatcher extends Matcher {
Expand All @@ -14,15 +15,16 @@ export class PackageNameMatcher extends Matcher {
return false;
}

if (matchPackageNames.includes(depName)) {
if (is.string(packageName) && matchPackageNames.includes(packageName)) {
return true;
}

if (
is.string(packageName) &&
process.env.RENOVATE_X_MATCH_PACKAGE_NAMES_MORE
) {
return matchPackageNames.includes(packageName);
if (matchPackageNames.includes(depName)) {
logger.once.warn(
{ packageName, depName },
'Use matchDepNames instead of matchPackageNames'
);
return true;
}

return false;
Expand Down
26 changes: 26 additions & 0 deletions lib/util/package-rules/package-patterns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,31 @@ describe('util/package-rules/package-patterns', () => {
);
expect(result).toBeFalse();
});

it('should match packageName', () => {
const result = packageNameMatcher.matches(
{
depName: 'abc',
packageName: 'def',
},
{
matchPackagePatterns: ['def'],
}
);
expect(result).toBeTrue();
});

it('should fall back to matching depName', () => {
const result = packageNameMatcher.matches(
{
depName: 'abc',
packageName: 'def',
},
{
matchPackagePatterns: ['abc'],
}
);
expect(result).toBeTrue();
});
});
});
38 changes: 23 additions & 15 deletions lib/util/package-rules/package-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import { regEx } from '../regex';
import { Matcher } from './base';
import { massagePattern } from './utils';

function matchPatternsAgainstName(
matchPackagePatterns: string[],
name: string
): boolean {
let isMatch = false;
for (const packagePattern of matchPackagePatterns) {
if (isPackagePatternMatch(packagePattern, name)) {
isMatch = true;
}
}
return isMatch;
}

export class PackagePatternsMatcher extends Matcher {
override matches(
{ depName, packageName }: PackageRuleInputConfig,
Expand All @@ -18,26 +31,21 @@ export class PackagePatternsMatcher extends Matcher {
return false;
}

const namesToMatchAgainst = [depName];

if (
is.string(packageName) &&
process.env.RENOVATE_X_MATCH_PACKAGE_NAMES_MORE
matchPatternsAgainstName(matchPackagePatterns, packageName)
) {
namesToMatchAgainst.push(packageName);
return true;
}

let isMatch = false;
for (const packagePattern of matchPackagePatterns) {
if (
namesToMatchAgainst.some((p) =>
isPackagePatternMatch(packagePattern, p)
)
) {
isMatch = true;
}
if (matchPatternsAgainstName(matchPackagePatterns, depName)) {
logger.once.warn(
{ packageName, depName },
'Use matchDepPatterns instead of matchPackagePatterns'
);
return true;
}
return isMatch;

return false;
}

override excludes(
Expand Down