Skip to content

Commit

Permalink
subdoc parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dandlezzz committed Oct 14, 2024
1 parent a0e2308 commit 7727b25
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions .github/scripts/validate-and-merge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,9 @@ async function validateAndMerge() {
const yamlDocuments = yaml.loadAll(content);

for (const document of yamlDocuments) {
const isValid = requiredKeys.every(key => key in document);

const isValid = validateSubdocument(document);
if (!isValid) {
console.log(JSON.parse(document) + ' is missing required keys');
return;
}

if (!Array.isArray(document.categories) || document.categories.length === 0) {
console.log('Categories must be a non-empty array');
console.log(`Invalid subdocument: ${JSON.stringify(document)}`);
return;
}
}
Expand All @@ -88,4 +82,20 @@ async function validateAndMerge() {
}
}

function validateSubdocument(subdocument) {
const isValid = requiredKeys.every(key => key in subdocument);

if (!isValid) {
console.log(`Subdocument is missing required keys: ${JSON.stringify(subdocument)}`);
return false;
}

if (!Array.isArray(subdocument.categories) || subdocument.categories.length === 0) {
console.log('Categories must be a non-empty array');
return false;
}

return true;
}

validateAndMerge();

0 comments on commit 7727b25

Please sign in to comment.