diff --git a/lib/modules/datasource/index.spec.ts b/lib/modules/datasource/index.spec.ts index f5e911dd483f5d..3580453fd6ad54 100644 --- a/lib/modules/datasource/index.spec.ts +++ b/lib/modules/datasource/index.spec.ts @@ -8,7 +8,12 @@ import { ExternalHostError } from '../../types/errors/external-host-error'; import { loadModules } from '../../util/modules'; import datasources from './api'; import { Datasource } from './datasource'; -import type { DatasourceApi, GetReleasesConfig, ReleaseResult } from './types'; +import type { + DatasourceApi, + DigestConfig, + GetReleasesConfig, + ReleaseResult, +} from './types'; import { getDatasourceList, getDatasources, @@ -228,6 +233,27 @@ describe('modules/datasource/index', () => { expect(supportsDigests(datasource)).toBeTrue(); expect(await getDigest({ datasource, depName })).toBe('123'); }); + + it('returns replacementName if defined', async () => { + class TestDatasource extends DummyDatasource { + override getDigest( + config: DigestConfig, + newValue?: string + ): Promise { + return Promise.resolve(config.packageName); + } + } + datasources.set(datasource, new TestDatasource()); + + expect( + await getDigest({ + datasource: datasource, + packageName: 'pkgName', + depName: depName, + replacementName: 'replacement', + }) + ).toBe('replacement'); + }); }); describe('Metadata', () => { diff --git a/lib/modules/datasource/index.ts b/lib/modules/datasource/index.ts index c3472be9ab6687..7cba3f147d8d33 100644 --- a/lib/modules/datasource/index.ts +++ b/lib/modules/datasource/index.ts @@ -433,7 +433,8 @@ function getDigestConfig( config: GetDigestInputConfig ): DigestConfig { const { currentValue, currentDigest } = config; - const packageName = config.packageName ?? config.depName; + const packageName = + config.replacementName ?? config.packageName ?? config.depName; const [registryUrl] = resolveRegistryUrls( datasource, config.defaultRegistryUrls, diff --git a/lib/modules/datasource/types.ts b/lib/modules/datasource/types.ts index 6fde73ae3f41e0..054a68e64d28c1 100644 --- a/lib/modules/datasource/types.ts +++ b/lib/modules/datasource/types.ts @@ -9,6 +9,7 @@ export interface GetDigestInputConfig { additionalRegistryUrls?: string[]; currentValue?: string; currentDigest?: string; + replacementName?: string; } export interface DigestConfig {