Skip to content

Commit 0a46e66

Browse files
TrottBethGriggs
authored andcommitted
tools: use mailmap for find-inactive-collaborators
The current version of find-inactive-collaborators can generate a false positive if the mailmap entry for a collaborator does not match the entry in the README. (We should probably lint or otherwise check for that sort of mismatch but regardless, it is relatively easy to avoid having find-inactive-collaborators tripped up by it, so let's fix that too, which is this commit.) PR-URL: #39432 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent aa1dfb3 commit 0a46e66

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

tools/find-inactive-collaborators.mjs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,33 @@ async function runGitCommand(cmd, mapFn) {
2222
const errorHandler = new Promise(
2323
(_, reject) => childProcess.on('error', reject)
2424
);
25-
const returnedSet = new Set();
25+
let returnValue = mapFn ? new Set() : '';
2626
await Promise.race([errorHandler, Promise.resolve()]);
27+
// If no mapFn, return the value. If there is a mapFn, use it to make a Set to
28+
// return.
2729
for await (const line of lines) {
2830
await Promise.race([errorHandler, Promise.resolve()]);
29-
const val = mapFn(line);
30-
if (val) {
31-
returnedSet.add(val);
31+
if (mapFn) {
32+
const val = mapFn(line);
33+
if (val) {
34+
returnValue.add(val);
35+
}
36+
} else {
37+
returnValue += line;
3238
}
3339
}
34-
return Promise.race([errorHandler, Promise.resolve(returnedSet)]);
40+
return Promise.race([errorHandler, Promise.resolve(returnValue)]);
3541
}
3642

3743
// Get all commit authors during the time period.
3844
const authors = await runGitCommand(
39-
`git shortlog -n -s --max-count="${SINCE}" HEAD`,
45+
`git shortlog -n -s --email --max-count="${SINCE}" HEAD`,
4046
(line) => line.trim().split('\t', 2)[1]
4147
);
4248

4349
// Get all commit landers during the time period.
4450
const landers = await runGitCommand(
45-
`git shortlog -n -s -c --max-count="${SINCE}" HEAD`,
51+
`git shortlog -n -s -c --email --max-count="${SINCE}" HEAD`,
4652
(line) => line.trim().split('\t', 2)[1]
4753
);
4854

@@ -52,7 +58,7 @@ const approvingReviewers = await runGitCommand(
5258
(line) => /^ Reviewed-By: ([^<]+)/.exec(line)[1].trim()
5359
);
5460

55-
async function retrieveCollaboratorsFromReadme() {
61+
async function getCollaboratorsFromReadme() {
5662
const readmeText = readline.createInterface({
5763
input: fs.createReadStream(new URL('../README.md', import.meta.url)),
5864
crlfDelay: Infinity,
@@ -69,14 +75,22 @@ async function retrieveCollaboratorsFromReadme() {
6975
break;
7076
}
7177
if (line.startsWith('**') && isCollaborator) {
72-
returnedArray.push(line.split('**', 2)[1].trim());
78+
const [, name, email] = /^\*\*([^*]+)\*\* &lt;(.+)&gt;/.exec(line);
79+
const mailmap = await runGitCommand(
80+
`git check-mailmap '${name} <${email}>'`
81+
);
82+
returnedArray.push({
83+
name,
84+
email,
85+
mailmap,
86+
});
7387
}
7488
}
7589
return returnedArray;
7690
}
7791

7892
// Get list of current collaborators from README.md.
79-
const collaborators = await retrieveCollaboratorsFromReadme();
93+
const collaborators = await getCollaboratorsFromReadme();
8094

8195
console.log(`In the last ${SINCE} commits:\n`);
8296
console.log(`* ${authors.size.toLocaleString()} authors have made commits.`);
@@ -85,10 +99,10 @@ console.log(`* ${approvingReviewers.size.toLocaleString()} reviewers have approv
8599
console.log(`* ${collaborators.length.toLocaleString()} collaborators currently in the project.`);
86100

87101
const inactive = collaborators.filter((collaborator) =>
88-
!authors.has(collaborator) &&
89-
!landers.has(collaborator) &&
90-
!approvingReviewers.has(collaborator)
91-
);
102+
!authors.has(collaborator.mailmap) &&
103+
!landers.has(collaborator.mailmap) &&
104+
!approvingReviewers.has(collaborator.name)
105+
).map((collaborator) => collaborator.name);
92106

93107
if (inactive.length) {
94108
console.log('\nInactive collaborators:\n');

0 commit comments

Comments
 (0)