diff --git a/lib/config/migrations/custom/datasource-migration.ts b/lib/config/migrations/custom/datasource-migration.ts index b20445935a09d614b425a9e90843887930a8873d..d9158db39c2dc43b101ab8ff1254c9d2125f15f9 100644 --- a/lib/config/migrations/custom/datasource-migration.ts +++ b/lib/config/migrations/custom/datasource-migration.ts @@ -6,17 +6,18 @@ export class DatasourceMigration extends AbstractMigration { override run(value: unknown): void { if (is.string(value)) { - let newValue = value; - switch (newValue) { - case 'adoptium-java': - newValue = 'java-version'; - break; - case 'dotnet': - newValue = 'dotnet-version'; - break; - } - + const newValue = migrateDatasource(value); this.rewrite(newValue); } } } + +export function migrateDatasource(value: string): string { + switch (value) { + case 'adoptium-java': + return 'java-version'; + case 'dotnet': + return 'dotnet-version'; + } + return value; +} diff --git a/lib/modules/manager/regex/index.spec.ts b/lib/modules/manager/regex/index.spec.ts index d683f544830c37b7cfaf0ad246dee4f4721da5c6..1146c533f20d22151fe6e7a28822ceb17077b900 100644 --- a/lib/modules/manager/regex/index.spec.ts +++ b/lib/modules/manager/regex/index.spec.ts @@ -1,3 +1,4 @@ +import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../test/fixtures'; import { logger } from '../../../logger'; import type { CustomExtractConfig } from '../types'; @@ -449,4 +450,32 @@ describe('modules/manager/regex/index', () => { ], }); }); + + it('migrates', async () => { + const config: CustomExtractConfig = { + matchStrings: [ + '# renovate: datasource=(?<datasource>[a-z-]+?)(?: (?:packageName|lookupName)=(?<packageName>.+?))?(?: versioning=(?<versioning>[a-z-]+?))?\\sRUN install-[a-z]+? (?<depName>[a-z-]+?) (?<currentValue>.+?)(?:\\s|$)', + ], + versioningTemplate: + '{{#if versioning}}{{versioning}}{{else}}semver{{/if}}', + }; + const res = await extractPackageFile( + codeBlock` + # renovate: datasource=dotnet packageName=dotnet-runtime + RUN install-tool dotnet 6.0.13 + `, + 'Dockerfile', + config + ); + expect(res).toMatchObject({ + deps: [ + { + depName: 'dotnet', + packageName: 'dotnet-runtime', + currentValue: '6.0.13', + datasource: 'dotnet-version', + }, + ], + }); + }); }); diff --git a/lib/modules/manager/regex/utils.ts b/lib/modules/manager/regex/utils.ts index fbe31c506b1750794ece8679a106fd6ff84fc90f..e54317e43db4d563c4153bdcdf8c924c4f2435e4 100644 --- a/lib/modules/manager/regex/utils.ts +++ b/lib/modules/manager/regex/utils.ts @@ -1,5 +1,6 @@ import { URL } from 'url'; import is from '@sindresorhus/is'; +import { migrateDatasource } from '../../../config/migrations/custom/datasource-migration'; import type { RegexManagerTemplates } from '../../../config/types'; import { logger } from '../../../logger'; import * as template from '../../../util/template'; @@ -35,6 +36,9 @@ function updateDependency( logger.warn({ value }, 'Invalid regex manager registryUrl'); } break; + case 'datasource': + dependency.datasource = migrateDatasource(value); + break; default: dependency[field] = value; break;