test(docs-infra): expand select glob patterns in `verify-docs-codeownership.js` (#32360)

This allows the script to recognise some matches that it would miss
before and avoid listing them as missing.

Ideally, the script should be able to understand the globs in
`CODEOWNERS` and correctly find matching file-system paths.However, for
the limited purposes of the script (and for just a couple of relevant
globs), implementing this would be an overkill.

Implemented the "manual expansion" instead.
(We might revisit, if the needs change.)

PR Close #32360
This commit is contained in:
George Kalpakas 2019-08-28 10:13:57 +03:00 committed by Misko Hevery
parent afc6ab5442
commit c507e4907d
1 changed files with 13 additions and 0 deletions

View File

@ -71,6 +71,11 @@ function getPathsFromCodeowners() {
// different kinds of matches (guide, image, example) later (see `isImage`/`isExample` below).
const aioGuidesOrImagesPathRe = /^\/aio\/content\/(?:(images\/)?guide|(examples))\/([^\s\*/]+)/;
const pkgExamplesPathRe = /^\/packages\/examples\/([^\s\*/]+)/;
const manualGlobExpansions = {
// `CODEOWNERS` has a glob to match all `testing/` directories, so no specific glob for
// `packages/examples/testing/` is necessary.
'testing/**': ['/packages/examples/testing/**'],
};
const aioGuides = [];
const aioImages = [];
@ -83,6 +88,14 @@ function getPathsFromCodeowners() {
split('\n').
map(l => l.trim());
// Manually expand globs to known matching patterns.
for (const [glob, expansions] of Object.entries(manualGlobExpansions)) {
const matchingLine = lines.find(l => l.startsWith(`${glob} `));
if (matchingLine !== undefined) {
lines.push(...expansions);
}
}
// Collect `aio/` guides/images/examples.
lines.
map(l => l.match(aioGuidesOrImagesPathRe)).