Skip to content

Commit

Permalink
test(lib/data): schemas for changelog and source urls (#32151)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
RahulGautamSingh and viceice authored Oct 30, 2024
1 parent 9bb91c8 commit 95efd9f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/data/changelog-urls.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions lib/data/source-urls.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 5 additions & 3 deletions lib/modules/datasource/metadata-manual.ts
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
4 changes: 2 additions & 2 deletions test/validate-schemas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe('validate-schemas', () => {
);

for (const schemaFile of schemaFiles) {
const correspondingDatFileName = schemaFile.replace('-schema', '');
const correspondingDataFileName = schemaFile.replace('-schema', '');
const schemaName = `${schemaFile
.replace('.json', '')
.split('-')
.map(capitalize)
.join('')}` as keyof typeof Schemas;
schemasAndJsonFiles.push({
schemaName,
dataFileName: correspondingDatFileName,
dataFileName: correspondingDataFileName,
});
}

Expand Down
17 changes: 17 additions & 0 deletions tools/schemas/changelog-urls-schema.json
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions tools/schemas/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
17 changes: 17 additions & 0 deletions tools/schemas/source-urls-schema.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 95efd9f

Please sign in to comment.