From 7145304f2f381cc763f7719bae368b5d2aea03f2 Mon Sep 17 00:00:00 2001 From: meesh Date: Wed, 10 Apr 2024 10:02:57 -0400 Subject: [PATCH] Support multiple owners per glob (#23) --- badges/coverage.svg | 2 +- dist/index.js | 15 +++++++++------ src/api.ts | 15 ++++++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/badges/coverage.svg b/badges/coverage.svg index 7c68c39..57789f7 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -Coverage: 19.49%Coverage19.49% \ No newline at end of file +Coverage: 19.16%Coverage19.16% \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 0ee2f66..c86e24c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32806,13 +32806,15 @@ async function getCodeowners(client, prNumber, filePath = 'CODEOWNERS') { .filter(l => l.trim().length > 0) .filter(l => !l.startsWith('#')) .map(l => l.split(' ')) - .filter(([glob, team]) => { - if (team === undefined) { + .filter(([glob, ...teams]) => { + if (teams.length === 0 || + (teams.length === 1 && teams[0] === undefined)) { core.warning(`CODEOWNERS had glob ${glob} w/o matching team`); + return false; } - return team !== undefined; + return true; }) - .map(([glob, team]) => { + .map(([glob, ...teams]) => { // do some munging to support CODEOWNER format globs let finalGlob = glob; // convert directories like foo/ to foo/** @@ -32826,8 +32828,9 @@ async function getCodeowners(client, prNumber, filePath = 'CODEOWNERS') { finalGlob += '/**'; } } - return [finalGlob, team]; - }); + return teams.map(team => [finalGlob, team]); + }) + .flat(1); if (!codeowners.length) { core.warning(`Pull request #${prNumber} has no codeowners`); return []; diff --git a/src/api.ts b/src/api.ts index f1c730c..2b3af16 100644 --- a/src/api.ts +++ b/src/api.ts @@ -103,14 +103,18 @@ export async function getCodeowners( .filter(l => l.trim().length > 0) .filter(l => !l.startsWith('#')) .map(l => l.split(' ')) - .filter(([glob, team]) => { - if (team === undefined) { + .filter(([glob, ...teams]) => { + if ( + teams.length === 0 || + (teams.length === 1 && teams[0] === undefined) + ) { core.warning(`CODEOWNERS had glob ${glob} w/o matching team`) + return false } - return team !== undefined + return true }) - .map(([glob, team]) => { + .map(([glob, ...teams]) => { // do some munging to support CODEOWNER format globs let finalGlob = glob @@ -125,8 +129,9 @@ export async function getCodeowners( } } - return [finalGlob, team] + return teams.map(team => [finalGlob, team]) }) + .flat(1) if (!codeowners.length) { core.warning(`Pull request #${prNumber} has no codeowners`)