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

test(lib/data): schemas for changelog and source urls #32151

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}