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 <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent aa1dfb3 commit 0a46e66

1 file changed

Lines changed: 28 additions & 14 deletions

File tree

‎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
consterrorHandler=newPromise(
2323
(_,reject)=>childProcess.on('error',reject)
2424
);
25-
constreturnedSet=newSet();
25+
letreturnValue=mapFn ? newSet() : '';
2626
awaitPromise.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
forawait(constlineoflines){
2830
awaitPromise.race([errorHandler,Promise.resolve()]);
29-
constval=mapFn(line);
30-
if(val){
31-
returnedSet.add(val);
31+
if(mapFn){
32+
constval=mapFn(line);
33+
if(val){
34+
returnValue.add(val);
35+
}
36+
}else{
37+
returnValue+=line;
3238
}
3339
}
34-
returnPromise.race([errorHandler,Promise.resolve(returnedSet)]);
40+
returnPromise.race([errorHandler,Promise.resolve(returnValue)]);
3541
}
3642

3743
// Get all commit authors during the time period.
3844
constauthors=awaitrunGitCommand(
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
constlanders=awaitrunGitCommand(
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-
asyncfunctionretrieveCollaboratorsFromReadme(){
61+
asyncfunctiongetCollaboratorsFromReadme(){
5662
constreadmeText=readline.createInterface({
5763
input: fs.createReadStream(newURL('../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+
constmailmap=awaitrunGitCommand(
80+
`git check-mailmap '${name} <${email}>'`
81+
);
82+
returnedArray.push({
83+
name,
84+
email,
85+
mailmap,
86+
});
7387
}
7488
}
7589
returnreturnedArray;
7690
}
7791

7892
// Get list of current collaborators from README.md.
79-
constcollaborators=awaitretrieveCollaboratorsFromReadme();
93+
constcollaborators=awaitgetCollaboratorsFromReadme();
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
constinactive=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)