Skip to content

Commit

Permalink
feat(datasource): rename dotnet to dotnet-version (#20244)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Feb 10, 2023
1 parent b48a3d3 commit 93c3fd5
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 26 deletions.
14 changes: 14 additions & 0 deletions lib/config/migrations/custom/datasource-migration.spec.ts
@@ -0,0 +1,14 @@
import { DatasourceMigration } from './datasource-migration';

describe('config/migrations/custom/datasource-migration', () => {
it('should migrate properly', () => {
expect(DatasourceMigration).toMigrate(
{
datasource: 'dotnet',
},
{
datasource: 'dotnet-version',
}
);
});
});
14 changes: 14 additions & 0 deletions lib/config/migrations/custom/datasource-migration.ts
@@ -0,0 +1,14 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class DatasourceMigration extends AbstractMigration {
override readonly propertyName = 'datasource';

override run(value: unknown): void {
if (is.string(value)) {
const newValue = value === 'dotnet' ? 'dotnet-version' : value;

this.rewrite(newValue);
}
}
}
14 changes: 14 additions & 0 deletions lib/config/migrations/custom/match-datasources-migration.spec.ts
@@ -0,0 +1,14 @@
import { MatchDatasourcesMigration } from './match-datasources-migration';

describe('config/migrations/custom/match-datasources-migration', () => {
it('should migrate properly', () => {
expect(MatchDatasourcesMigration).toMigrate(
{
matchDatasources: ['dotnet'],
},
{
matchDatasources: ['dotnet-version'],
}
);
});
});
18 changes: 18 additions & 0 deletions lib/config/migrations/custom/match-datasources-migration.ts
@@ -0,0 +1,18 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class MatchDatasourcesMigration extends AbstractMigration {
override readonly propertyName = 'matchDatasources';

override run(value: unknown): void {
if (Array.isArray(value)) {
const newValue = value
.filter(is.nonEmptyString)
.map((datasource) =>
datasource === 'dotnet' ? 'dotnet-version' : datasource
);

this.rewrite(newValue);
}
}
}
5 changes: 5 additions & 0 deletions lib/config/migrations/migrations-service.ts
Expand Up @@ -15,6 +15,7 @@ import { BranchNameMigration } from './custom/branch-name-migration';
import { BranchPrefixMigration } from './custom/branch-prefix-migration';
import { CompatibilityMigration } from './custom/compatibility-migration';
import { ComposerIgnorePlatformReqsMigration } from './custom/composer-ignore-platform-reqs-migration';
import { DatasourceMigration } from './custom/datasource-migration';
import { DepTypesMigration } from './custom/dep-types-migration';
import { DryRunMigration } from './custom/dry-run-migration';
import { EnabledManagersMigration } from './custom/enabled-managers-migration';
Expand All @@ -23,6 +24,7 @@ import { GoModTidyMigration } from './custom/go-mod-tidy-migration';
import { HostRulesMigration } from './custom/host-rules-migration';
import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration';
import { IgnoreNpmrcFileMigration } from './custom/ignore-npmrc-file-migration';
import { MatchDatasourcesMigration } from './custom/match-datasources-migration';
import { MatchStringsMigration } from './custom/match-strings-migration';
import { NodeMigration } from './custom/node-migration';
import { PackageFilesMigration } from './custom/package-files-migration';
Expand Down Expand Up @@ -71,6 +73,7 @@ export class MigrationsService {
]);

static readonly renamedProperties: ReadonlyMap<string, string> = new Map([
['dotnet', 'dotnet-version'],
['endpoints', 'hostRules'],
['excludedPackageNames', 'excludePackageNames'],
['exposeEnv', 'exposeAllEnv'],
Expand Down Expand Up @@ -136,6 +139,8 @@ export class MigrationsService {
PackageRulesMigration,
NodeMigration,
SemanticPrefixMigration,
MatchDatasourcesMigration,
DatasourceMigration,
];

static run(originalConfig: RenovateConfig): RenovateConfig {
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/api.ts
Expand Up @@ -14,7 +14,7 @@ import { DartDatasource } from './dart';
import { DartVersionDatasource } from './dart-version';
import { DenoDatasource } from './deno';
import { DockerDatasource } from './docker';
import { DotnetDatasource } from './dotnet';
import { DotnetVersionDatasource } from './dotnet-version';
import { FlutterVersionDatasource } from './flutter-version';
import { GalaxyDatasource } from './galaxy';
import { GalaxyCollectionDatasource } from './galaxy-collection';
Expand Down Expand Up @@ -71,7 +71,7 @@ api.set(DartDatasource.id, new DartDatasource());
api.set(DartVersionDatasource.id, new DartVersionDatasource());
api.set(DenoDatasource.id, new DenoDatasource());
api.set(DockerDatasource.id, new DockerDatasource());
api.set(DotnetDatasource.id, new DotnetDatasource());
api.set(DotnetVersionDatasource.id, new DotnetVersionDatasource());
api.set(FlutterVersionDatasource.id, new FlutterVersionDatasource());
api.set(GalaxyDatasource.id, new GalaxyDatasource());
api.set(GalaxyCollectionDatasource.id, new GalaxyCollectionDatasource());
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { getPkgReleases } from '..';
import { Fixtures } from '../../../../test/fixtures';
import * as httpMock from '../../../../test/http-mock';
import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages';
import { DotnetDatasource } from '.';
import { DotnetVersionDatasource } from '.';

const releasesIndex = Fixtures.getJson('releases-index.json');
const releases7_0 = Fixtures.getJson('releases-7.0.json');
Expand All @@ -13,12 +13,12 @@ const releases3_1 = Fixtures.getJson('releases-3.1.json');
const baseUrl =
'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata';

describe('modules/datasource/dotnet/index', () => {
describe('modules/datasource/dotnet-version/index', () => {
describe('getReleases', () => {
it('returns null for non-dotnet package', async () => {
expect(
await getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'non-dotnet',
})
).toBeNull();
Expand All @@ -29,7 +29,7 @@ describe('modules/datasource/dotnet/index', () => {

expect(
await getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-sdk',
})
).toBeNull();
Expand All @@ -45,7 +45,7 @@ describe('modules/datasource/dotnet/index', () => {

expect(
await getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-sdk',
})
).toBeNull();
Expand All @@ -56,7 +56,7 @@ describe('modules/datasource/dotnet/index', () => {

await expect(
getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-sdk',
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
Expand All @@ -72,7 +72,7 @@ describe('modules/datasource/dotnet/index', () => {

await expect(
getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-sdk',
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
Expand All @@ -83,7 +83,7 @@ describe('modules/datasource/dotnet/index', () => {

expect(
await getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-sdk',
})
).toBeNull();
Expand All @@ -99,7 +99,7 @@ describe('modules/datasource/dotnet/index', () => {

expect(
await getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-sdk',
})
).toBeNull();
Expand All @@ -120,7 +120,7 @@ describe('modules/datasource/dotnet/index', () => {
.reply(200, releases3_1);

const res = await getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-sdk',
});

Expand Down Expand Up @@ -154,7 +154,7 @@ describe('modules/datasource/dotnet/index', () => {
.reply(200, releases3_1);

const res = await getPkgReleases({
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
depName: 'dotnet-runtime',
});

Expand Down
Expand Up @@ -11,11 +11,11 @@ import {
DotnetReleasesSchema,
} from './schema';

export class DotnetDatasource extends Datasource {
static readonly id = 'dotnet';
export class DotnetVersionDatasource extends Datasource {
static readonly id = 'dotnet-version';

constructor() {
super(DotnetDatasource.id);
super(DotnetVersionDatasource.id);
}

override readonly caching = true;
Expand All @@ -27,7 +27,7 @@ export class DotnetDatasource extends Datasource {
];

@cache({
namespace: `datasource-${DotnetDatasource.id}`,
namespace: `datasource-${DotnetVersionDatasource.id}`,
key: ({ packageName }: GetReleasesConfig) => packageName,
ttlMinutes: 1440,
})
Expand Down Expand Up @@ -77,7 +77,7 @@ export class DotnetDatasource extends Datasource {
}

@cache({
namespace: `datasource-${DotnetDatasource.id}`,
namespace: `datasource-${DotnetVersionDatasource.id}`,
key: (releaseUrl: string, packageName: string) =>
`${releaseUrl}:${packageName}`,
ttlMinutes: 1440,
Expand All @@ -97,7 +97,7 @@ export class DotnetDatasource extends Datasource {

const body = raw?.body;
if (body) {
const type = DotnetDatasource.getType(packageName);
const type = DotnetVersionDatasource.getType(packageName);
const { releases: releases } = body;
result = releases
.filter(
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions lib/modules/manager/nuget/extract.spec.ts
Expand Up @@ -2,7 +2,7 @@ import upath from 'upath';
import { Fixtures } from '../../../../test/fixtures';
import { GlobalConfig } from '../../../config/global';
import type { RepoGlobalConfig } from '../../../config/types';
import { DotnetDatasource } from '../../datasource/dotnet';
import { DotnetVersionDatasource } from '../../datasource/dotnet-version';
import type { ExtractConfig } from '../types';
import { extractPackageFile } from '.';

Expand Down Expand Up @@ -250,7 +250,7 @@ describe('modules/manager/nuget/extract', () => {
currentValue: '5.0.302',
depName: 'dotnet-sdk',
depType: 'dotnet-sdk',
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
},
{
currentValue: '0.2.0',
Expand All @@ -273,7 +273,7 @@ describe('modules/manager/nuget/extract', () => {
currentValue: '5.0.302',
depName: 'dotnet-sdk',
depType: 'dotnet-sdk',
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
},
],
});
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/nuget/extract/global-manifest.ts
@@ -1,5 +1,5 @@
import { logger } from '../../../../logger';
import { DotnetDatasource } from '../../../datasource/dotnet';
import { DotnetVersionDatasource } from '../../../datasource/dotnet-version';
import { NugetDatasource } from '../../../datasource/nuget';
import type { PackageDependency, PackageFile } from '../../types';
import type { MsbuildGlobalManifest } from '../types';
Expand Down Expand Up @@ -31,7 +31,7 @@ export function extractMsbuildGlobalManifest(
depType: 'dotnet-sdk',
depName: 'dotnet-sdk',
currentValue: manifest.sdk?.version,
datasource: DotnetDatasource.id,
datasource: DotnetVersionDatasource.id,
});
}

Expand Down
7 changes: 5 additions & 2 deletions lib/modules/manager/nuget/index.ts
@@ -1,5 +1,5 @@
import type { ProgrammingLanguage } from '../../../constants';
import { DotnetDatasource } from '../../datasource/dotnet';
import { DotnetVersionDatasource } from '../../datasource/dotnet-version';
import { NugetDatasource } from '../../datasource/nuget';

export { extractPackageFile } from './extract';
Expand All @@ -17,4 +17,7 @@ export const defaultConfig = {
],
};

export const supportedDatasources = [DotnetDatasource.id, NugetDatasource.id];
export const supportedDatasources = [
DotnetVersionDatasource.id,
NugetDatasource.id,
];

0 comments on commit 93c3fd5

Please sign in to comment.