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 <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Rich Trott 2021-08-01 06:29:20 -07:00 committed by Node.js GitHub Bot
parent 533cafcf7e
commit dd18795997

View File

@ -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] = /^\*\*([^*]+)\*\* &lt;(.+)&gt;/.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;
}