From dd18795997df640923e7df9699f47a41032f74b0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 1 Aug 2021 06:29:20 -0700 Subject: [PATCH] tools: improve error detection in find-inactive-collaborators Previously, if the script failed to find a collaborator section in the README file, it would carry on with no results and no error. This detects the problem and throws an error. It is also more robust in that it will still work if the emeriti section ends up getting moved and does not immedaitely follow the collaborator section. PR-URL: https://github.com/nodejs/node/pull/39617 Reviewed-By: Luigi Pinca Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell --- tools/find-inactive-collaborators.mjs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/find-inactive-collaborators.mjs b/tools/find-inactive-collaborators.mjs index 282a49dc965..0d89d2869cf 100755 --- a/tools/find-inactive-collaborators.mjs +++ b/tools/find-inactive-collaborators.mjs @@ -64,16 +64,19 @@ async function getCollaboratorsFromReadme() { crlfDelay: Infinity, }); const returnedArray = []; - let processingCollaborators = false; + let foundCollaboratorHeading = false; for await (const line of readmeText) { - const isCollaborator = processingCollaborators && line.length; - if (line === '### Collaborators') { - processingCollaborators = true; - } - if (line === '### Collaborator emeriti') { - processingCollaborators = false; + // If we've found the collaborator heading already, stop processing at the + // next heading. + if (foundCollaboratorHeading && line.startsWith('#')) { break; } + + const isCollaborator = foundCollaboratorHeading && line.length; + + if (line === '### Collaborators') { + foundCollaboratorHeading = true; + } if (line.startsWith('**') && isCollaborator) { const [, name, email] = /^\*\*([^*]+)\*\* <(.+)>/.exec(line); const mailmap = await runGitCommand( @@ -89,6 +92,11 @@ async function getCollaboratorsFromReadme() { }); } } + + if (!foundCollaboratorHeading) { + throw new Error('Could not find Collaborator section of README'); + } + return returnedArray; }