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(replacement): datasource changes #17881

Merged
merged 8 commits into from
Sep 27, 2022
28 changes: 27 additions & 1 deletion lib/modules/datasource/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<string> {
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', () => {
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/datasource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/modules/datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface GetDigestInputConfig {
additionalRegistryUrls?: string[];
currentValue?: string;
currentDigest?: string;
replacementName?: string;
}

export interface DigestConfig {
Expand Down