Skip to content

Commit

Permalink
refactor: rename lookupName -> packageName (#14494)
Browse files Browse the repository at this point in the history
Renames `lookupName` to be `packageName`.

BREAKING CHANGE: Use `packageName` instead of `lookupName` if interacting with Renovate datasources directly.
  • Loading branch information
rarkins committed Mar 4, 2022
1 parent a61821b commit 143c9a6
Show file tree
Hide file tree
Showing 194 changed files with 1,109 additions and 1,023 deletions.
4 changes: 2 additions & 2 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -2329,9 +2329,9 @@ It will be compiled using Handlebars and the regex `groups` result.
If `extractVersion` cannot be captured with a named capture group in `matchString` then it can be defined manually using this field.
It will be compiled using Handlebars and the regex `groups` result.

### lookupNameTemplate
### packageNameTemplate

`lookupName` is used for looking up dependency versions.
`packageName` is used for looking up dependency versions.
It will be compiled using Handlebars and the regex `groups` result.
It will default to the value of `depName` if left unconfigured/undefined.

Expand Down
28 changes: 27 additions & 1 deletion lib/config/__snapshots__/migration.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ Object {
}
`;

exports[`config/migration it migrates regexManagers 1`] = `
Object {
"regexManagers": Array [
Object {
"fileMatch": Array [
"(^|/|\\\\.)Dockerfile$",
"(^|/)Dockerfile\\\\.[^/]*$",
],
"matchStrings": Array [
"# renovate: datasource=(?<datasource>[a-z-]+?) depName=(?<depName>[^\\\\s]+?)(?: lookupName=(?<packageName>[^\\\\s]+?))?(?: versioning=(?<versioning>[a-z-0-9]+?))?\\\\s(?:ENV|ARG) .+?_VERSION=\\"?(?<currentValue>.+?)\\"?\\\\s",
],
},
Object {
"fileMatch": Array [
"(^|/|\\\\.)Dockerfile$",
"(^|/)Dockerfile\\\\.[^/]*$",
],
"matchStrings": Array [
"# renovate: datasource=(?<datasource>[a-z-]+?) depName=(?<depName>[^\\\\s]+?)(?: lookupName=(?<holder>[^\\\\s]+?))?(?: versioning=(?<versioning>[a-z-0-9]+?))?\\\\s(?:ENV|ARG) .+?_VERSION=\\"?(?<currentValue>.+?)\\"?\\\\s",
],
"packageNameTemplate": "{{{holder}}}",
},
],
}
`;
exports[`config/migration migrateConfig(config, parentConfig) does not migrate multi days 1`] = `
Object {
"schedule": "after 5:00pm on wednesday and thursday",
Expand Down Expand Up @@ -95,7 +121,7 @@ Object {
"binarySource": "global",
"branchName": "{{{branchPrefix}}}{{{additionalBranchPrefix}}}{{{branchTopic}}}{{{packageFileDir}}}",
"branchPrefix": "renovate/",
"commitMessage": "{{#if semanticCommitType}}{{semanticCommitType}}{{#if semanticCommitScope}}({{semanticCommitScope}}){{/if}}: {{/if}}some commit message {{depName}}",
"commitMessage": "{{#if semanticCommitType}}{{semanticCommitType}}{{#if semanticCommitScope}}({{semanticCommitScope}}){{/if}}: {{/if}}some commit message {{depName}} {{packageName}}",
"constraints": Object {
"python": "3.7",
},
Expand Down
28 changes: 27 additions & 1 deletion lib/config/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ describe('config/migration', () => {
meteor: true,
autodiscover: 'true' as never,
schedule: 'on the last day of the month' as never,
commitMessage: '{{semanticPrefix}}some commit message {{depNameShort}}',
commitMessage:
'{{semanticPrefix}}some commit message {{depNameShort}} {{lookupName}}',
prTitle: '{{semanticPrefix}}some pr title',
semanticPrefix: 'fix(deps): ',
pathRules: [
Expand Down Expand Up @@ -669,6 +670,31 @@ describe('config/migration', () => {
expect(isMigrated).toBeTrue();
expect(migratedConfig).toEqual({ extends: ['local>org/renovate-config'] });
});
it('it migrates regexManagers', () => {
const config: RenovateConfig = {
regexManagers: [
{
fileMatch: ['(^|/|\\.)Dockerfile$', '(^|/)Dockerfile\\.[^/]*$'],
matchStrings: [
'# renovate: datasource=(?<datasource>[a-z-]+?) depName=(?<depName>[^\\s]+?)(?: lookupName=(?<lookupName>[^\\s]+?))?(?: versioning=(?<versioning>[a-z-0-9]+?))?\\s(?:ENV|ARG) .+?_VERSION="?(?<currentValue>.+?)"?\\s',
],
},
{
fileMatch: ['(^|/|\\.)Dockerfile$', '(^|/)Dockerfile\\.[^/]*$'],
matchStrings: [
'# renovate: datasource=(?<datasource>[a-z-]+?) depName=(?<depName>[^\\s]+?)(?: lookupName=(?<holder>[^\\s]+?))?(?: versioning=(?<versioning>[a-z-0-9]+?))?\\s(?:ENV|ARG) .+?_VERSION="?(?<currentValue>.+?)"?\\s',
],
lookupNameTemplate: '{{{holder}}}',
} as any,
],
};
const { isMigrated, migratedConfig } = configMigration.migrateConfig(
config,
defaultConfig
);
expect(isMigrated).toBeTrue();
expect(migratedConfig).toMatchSnapshot();
});

it('it migrates gradle-lite', () => {
const config: RenovateConfig = {
Expand Down
13 changes: 13 additions & 0 deletions lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export function migrateConfig(
(item) => item !== 'prEditNotification'
);
}
} else if (key === 'matchStrings' && is.array(val)) {
migratedConfig.matchStrings = val
.map(
(matchString) =>
is.string(matchString) &&
matchString.replace(regEx(/\(\?<lookupName>/g), '(?<packageName>')
)
.filter(Boolean);
} else if (key.startsWith('masterIssue')) {
const newKey = key.replace('masterIssue', 'dependencyDashboard');
migratedConfig[newKey] = val;
Expand Down Expand Up @@ -116,6 +124,11 @@ export function migrateConfig(
regEx(/{{baseDir}}/g),
'{{packageFileDir}}'
);
} else if (is.string(val) && val.includes('{{lookupName}}')) {
migratedConfig[key] = val.replace(
regEx(/{{lookupName}}/g),
'{{packageName}}'
);
} else if (is.string(val) && val.includes('{{depNameShort}}')) {
migratedConfig[key] = val.replace(
regEx(/{{depNameShort}}/g),
Expand Down
1 change: 1 addition & 0 deletions lib/config/migrations/migrations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class MigrationsService {
['multipleMajorPrs', 'separateMultipleMajor'],
['separatePatchReleases', 'separateMinorPatch'],
['versionScheme', 'versioning'],
['lookupNameTemplate', 'packageNameTemplate'],
]);

static readonly customMigrations: ReadonlyArray<MigrationConstructor> = [
Expand Down
4 changes: 2 additions & 2 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2093,9 +2093,9 @@ const options: RenovateOptions[] = [
env: false,
},
{
name: 'lookupNameTemplate',
name: 'packageNameTemplate',
description:
'Optional lookupName for extracted dependencies, else defaults to depName value. Valid only within a `regexManagers` object.',
'Optional packageName for extracted dependencies, else defaults to depName value. Valid only within a `regexManagers` object.',
type: 'string',
parent: 'regexManagers',
cli: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/regex-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const presets: Record<string, Preset> = {
{
fileMatch: ['(^|/|\\.)Dockerfile$', '(^|/)Dockerfile\\.[^/]*$'],
matchStrings: [
'# renovate: datasource=(?<datasource>[a-z-]+?) depName=(?<depName>[^\\s]+?)(?: lookupName=(?<lookupName>[^\\s]+?))?(?: versioning=(?<versioning>[a-z-0-9]+?))?\\s(?:ENV|ARG) .+?_VERSION="?(?<currentValue>.+?)"?\\s',
'# renovate: datasource=(?<datasource>[a-z-]+?) depName=(?<depName>[^\\s]+?)(?: (lookupName|packageName)=(?<packageName>[^\\s]+?))?(?: versioning=(?<versioning>[a-z-0-9]+?))?\\s(?:ENV|ARG) .+?_VERSION="?(?<currentValue>.+?)"?\\s',
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export interface CustomManager {
matchStringsStrategy?: string;
depNameTemplate?: string;
datasourceTemplate?: string;
lookupNameTemplate?: string;
packageNameTemplate?: string;
versioningTemplate?: string;
autoReplaceStringTemplate?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export async function validateConfig(
'matchStrings',
'matchStringsStrategy',
'depNameTemplate',
'lookupNameTemplate',
'packageNameTemplate',
'datasourceTemplate',
'versioningTemplate',
'registryUrlTemplate',
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/adoptium-java/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const defaultRegistryUrl = 'https://api.adoptium.net/';

export const datasource = 'adoptium-java';

export function getImageType(lookupName: string): string {
switch (lookupName) {
export function getImageType(packageName: string): string {
switch (packageName) {
case 'java-jre':
return 'jre';
default:
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/datasource/adoptium-java/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ export class AdoptiumJavaDatasource extends Datasource {

@cache({
namespace: `datasource-${datasource}`,
key: ({ registryUrl, lookupName }: GetReleasesConfig) =>
`${registryUrl}:${getImageType(lookupName)}`,
key: ({ registryUrl, packageName }: GetReleasesConfig) =>
`${registryUrl}:${getImageType(packageName)}`,
})
async getReleases({
registryUrl,
lookupName,
packageName,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const imageType = getImageType(lookupName);
const imageType = getImageType(packageName);
logger.trace(
{ registryUrl, lookupName, imageType },
{ registryUrl, packageName, imageType },
'fetching java release'
);
const url = `${registryUrl}v3/info/release_versions?page_size=${pageSize}&image_type=${imageType}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC&vendor=adoptium`;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/adoptium-java/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ It uses `image_type=<jre|jdk>&project=jdk&release_type=ga&sort_method=DATE&sort_

It only uses the first 50 pages with 50 items per page.

Use `java-jdk` or `java` as `lookupName` to get releases which come with the Java Development Kit.
Use `java-jdk` or `java` as `packageName` to get releases which come with the Java Development Kit.

Use `java-jre` as `lookupName` if you only want releases which come with the Java Runtime Environment.
Use `java-jre` as `packageName` if you only want releases which come with the Java Runtime Environment.
Currently only the LTS releases of Java come with the JRE.
20 changes: 10 additions & 10 deletions lib/modules/datasource/artifactory/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('modules/datasource/artifactory/index', () => {
const res = await getPkgReleases({
...testConfig,
datasource,
lookupName: testLookupName,
packageName: testLookupName,
});
expect(res?.releases).toHaveLength(4);
expect(res).toMatchSnapshot({
Expand All @@ -51,7 +51,7 @@ describe('modules/datasource/artifactory/index', () => {
const res = await getPkgReleases({
...testConfig,
datasource,
lookupName: testLookupName,
packageName: testLookupName,
});
expect(res?.releases).toHaveLength(4);
expect(res).toMatchSnapshot({
Expand All @@ -76,7 +76,7 @@ describe('modules/datasource/artifactory/index', () => {
registryUrls: [testRegistryUrl, secondRegistryUrl],
depName: testLookupName,
datasource,
lookupName: testLookupName,
packageName: testLookupName,
});
expect(res?.releases).toHaveLength(5);
expect(res).toMatchSnapshot();
Expand All @@ -86,11 +86,11 @@ describe('modules/datasource/artifactory/index', () => {
const res = await getPkgReleases({
datasource,
depName: testLookupName,
lookupName: testLookupName,
packageName: testLookupName,
});
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenCalledWith(
{ lookupName: 'project' },
{ packageName: 'project' },
'artifactory datasource requires custom registryUrl. Skipping datasource'
);
expect(res).toBeNull();
Expand All @@ -105,7 +105,7 @@ describe('modules/datasource/artifactory/index', () => {
await getPkgReleases({
...testConfig,
datasource,
lookupName: testLookupName,
packageName: testLookupName,
})
).toBeNull();
});
Expand All @@ -116,13 +116,13 @@ describe('modules/datasource/artifactory/index', () => {
await getPkgReleases({
...testConfig,
datasource,
lookupName: testLookupName,
packageName: testLookupName,
})
).toBeNull();
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).toHaveBeenCalledWith(
{
lookupName: 'project',
packageName: 'project',
registryUrl: 'https://jfrog.company.com/artifactory',
},
'artifactory: `Not Found` error'
Expand All @@ -135,7 +135,7 @@ describe('modules/datasource/artifactory/index', () => {
getPkgReleases({
...testConfig,
datasource,
lookupName: testLookupName,
packageName: testLookupName,
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});
Expand All @@ -148,7 +148,7 @@ describe('modules/datasource/artifactory/index', () => {
const res = await getPkgReleases({
...testConfig,
datasource,
lookupName: testLookupName,
packageName: testLookupName,
});
expect(res).toBeNull();
});
Expand Down
16 changes: 8 additions & 8 deletions lib/modules/datasource/artifactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ export class ArtifactoryDatasource extends Datasource {

@cache({
namespace: `datasource-${datasource}`,
key: ({ registryUrl, lookupName }: GetReleasesConfig) =>
`${registryUrl}:${lookupName}`,
key: ({ registryUrl, packageName }: GetReleasesConfig) =>
`${registryUrl}:${packageName}`,
})
async getReleases({
lookupName,
packageName,
registryUrl,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
if (!registryUrl) {
logger.warn(
{ lookupName },
{ packageName },
'artifactory datasource requires custom registryUrl. Skipping datasource'
);
return null;
}

const url = joinUrlParts(registryUrl, lookupName);
const url = joinUrlParts(registryUrl, packageName);

const result: ReleaseResult = {
releases: [],
Expand Down Expand Up @@ -82,12 +82,12 @@ export class ArtifactoryDatasource extends Datasource {

if (result.releases.length) {
logger.trace(
{ registryUrl, lookupName, versions: result.releases.length },
{ registryUrl, packageName, versions: result.releases.length },
'artifactory: Found versions'
);
} else {
logger.trace(
{ registryUrl, lookupName },
{ registryUrl, packageName },
'artifactory: No versions found'
);
}
Expand All @@ -96,7 +96,7 @@ export class ArtifactoryDatasource extends Datasource {
if (err instanceof HttpError) {
if (err.response?.statusCode === 404) {
logger.warn(
{ registryUrl, lookupName },
{ registryUrl, packageName },
'artifactory: `Not Found` error'
);
return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/artifactory/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Artifactory is the recommended registry for Conan packages.

This datasource returns releases from given custom `registryUrl`(s).

The target URL is composed by the `registryUrl` and the `lookupName`, which defaults to `depName` when `lookupName` is not defined.
The target URL is composed by the `registryUrl` and the `packageName`, which defaults to `depName` when `packageName` is not defined.

The release timestamp is taken from the date in the directory listing, and is assumed to be in UTC time.
12 changes: 6 additions & 6 deletions lib/modules/datasource/aws-machine-image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export class AwsMachineImageDataSource extends Datasource {

@cache({
namespace: `datasource-${AwsMachineImageDataSource.id}`,
key: ({ lookupName }: GetReleasesConfig, newValue: string) =>
`getDigest:${lookupName}:${newValue ?? ''}`,
key: ({ packageName }: GetReleasesConfig, newValue: string) =>
`getDigest:${packageName}:${newValue ?? ''}`,
})
override async getDigest(
{ lookupName: serializedAmiFilter }: GetReleasesConfig,
{ packageName: serializedAmiFilter }: GetReleasesConfig,
newValue?: string
): Promise<string | null> {
const images = await this.getSortedAwsMachineImages(serializedAmiFilter);
Expand All @@ -90,16 +90,16 @@ export class AwsMachineImageDataSource extends Datasource {
return null;
}

const res = await this.getReleases({ lookupName: serializedAmiFilter });
const res = await this.getReleases({ packageName: serializedAmiFilter });
return res?.releases?.[0]?.newDigest ?? /* istanbul ignore next */ null;
}

@cache({
namespace: `datasource-${AwsMachineImageDataSource.id}`,
key: ({ lookupName }: GetReleasesConfig) => `getReleases:${lookupName}`,
key: ({ packageName }: GetReleasesConfig) => `getReleases:${packageName}`,
})
async getReleases({
lookupName: serializedAmiFilter,
packageName: serializedAmiFilter,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const images = await this.getSortedAwsMachineImages(serializedAmiFilter);
const latestImage = images[images.length - 1];
Expand Down
Loading

0 comments on commit 143c9a6

Please sign in to comment.