From 95efd9f6fe21b16d71f5e5fc1b0cc38608325431 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh <rahultesnik@gmail.com> Date: Wed, 30 Oct 2024 13:49:48 +0530 Subject: [PATCH] test(lib/data): schemas for changelog and source urls (#32151) Co-authored-by: Michael Kriese <michael.kriese@visualon.de> --- lib/data/changelog-urls.json | 1 + lib/data/source-urls.json | 1 + lib/modules/datasource/metadata-manual.ts | 8 +++++--- test/validate-schemas.spec.ts | 4 ++-- tools/schemas/changelog-urls-schema.json | 17 +++++++++++++++++ tools/schemas/schema.ts | 12 ++++++++++++ tools/schemas/source-urls-schema.json | 17 +++++++++++++++++ 7 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 tools/schemas/changelog-urls-schema.json create mode 100644 tools/schemas/source-urls-schema.json diff --git a/lib/data/changelog-urls.json b/lib/data/changelog-urls.json index cf5f0d219b..d0100044ff 100644 --- a/lib/data/changelog-urls.json +++ b/lib/data/changelog-urls.json @@ -1,4 +1,5 @@ { + "$schema": "../../tools/schemas/changelog-urls-schema.json", "npm": { "babel-preset-react-app": "https://github.com/facebook/create-react-app/releases", "firebase": "https://firebase.google.com/support/release-notes/js", diff --git a/lib/data/source-urls.json b/lib/data/source-urls.json index d4e68ccb50..9ec7c57129 100644 --- a/lib/data/source-urls.json +++ b/lib/data/source-urls.json @@ -1,4 +1,5 @@ { + "$schema": "../../tools/schemas/source-urls-schema.json", "orb": { "cypress-io/cypress": "https://github.com/cypress-io/circleci-orb", "hutson/library-release-workflows": "https://github.com/hyper-expanse/library-release-workflows" diff --git a/lib/modules/datasource/metadata-manual.ts b/lib/modules/datasource/metadata-manual.ts index e1b8be1337..064453499c 100644 --- a/lib/modules/datasource/metadata-manual.ts +++ b/lib/modules/datasource/metadata-manual.ts @@ -1,13 +1,15 @@ -import changelogUrls from '../../data/changelog-urls.json'; -import sourceUrls from '../../data/source-urls.json'; +import changelogUrlsJson from '../../data/changelog-urls.json'; +import sourceUrlsJson from '../../data/source-urls.json'; +const { $schema: changelogSchema, ...changelogUrls } = changelogUrlsJson; // Only necessary when the changelog data cannot be found in the package's source repository export const manualChangelogUrls: Record< string, Record<string, string> > = changelogUrls; -// Only necessary if the datasource is unable to locate the source URL itself +const { $schema: sourceUrlSchema, ...sourceUrls } = sourceUrlsJson; +// Only necessary when the changelog data cannot be found in the package's source repository export const manualSourceUrls: Record< string, Record<string, string> diff --git a/test/validate-schemas.spec.ts b/test/validate-schemas.spec.ts index e7f424570b..e023e476b6 100644 --- a/test/validate-schemas.spec.ts +++ b/test/validate-schemas.spec.ts @@ -18,7 +18,7 @@ describe('validate-schemas', () => { ); for (const schemaFile of schemaFiles) { - const correspondingDatFileName = schemaFile.replace('-schema', ''); + const correspondingDataFileName = schemaFile.replace('-schema', ''); const schemaName = `${schemaFile .replace('.json', '') .split('-') @@ -26,7 +26,7 @@ describe('validate-schemas', () => { .join('')}` as keyof typeof Schemas; schemasAndJsonFiles.push({ schemaName, - dataFileName: correspondingDatFileName, + dataFileName: correspondingDataFileName, }); } diff --git a/tools/schemas/changelog-urls-schema.json b/tools/schemas/changelog-urls-schema.json new file mode 100644 index 0000000000..eb9c912a3b --- /dev/null +++ b/tools/schemas/changelog-urls-schema.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json-schema.org/draft-04/schema#", + "type": "object", + "patternProperties": { + "^[a-zA-Z-]+$": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9. -/:@]+$": { + "type": "string", + "format": "uri" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false +} diff --git a/tools/schemas/schema.ts b/tools/schemas/schema.ts index 8609e3582e..a37f6ea8f0 100644 --- a/tools/schemas/schema.ts +++ b/tools/schemas/schema.ts @@ -52,3 +52,15 @@ export const ReplacementsSchema = z all: AllSchema, }) .catchall(RuleSetSchema); + +export const ChangelogUrlsSchema = z + .object({ + $schema: z.string(), + }) + .catchall(z.record(z.string(), z.string().url())); + +export const SourceUrlsSchema = z + .object({ + $schema: z.string(), + }) + .catchall(z.record(z.string(), z.string().url())); diff --git a/tools/schemas/source-urls-schema.json b/tools/schemas/source-urls-schema.json new file mode 100644 index 0000000000..eb9c912a3b --- /dev/null +++ b/tools/schemas/source-urls-schema.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json-schema.org/draft-04/schema#", + "type": "object", + "patternProperties": { + "^[a-zA-Z-]+$": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9. -/:@]+$": { + "type": "string", + "format": "uri" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false +} -- GitLab