Skip to content

Commit 3cd9f5e

Browse files
Trotttargos
authored andcommitted
tools: add find-inactive-collaborators.js
The plan is to eventually call this script with a scheduled GitHub Action that could automatically open pull requests to move collaborators to emeritus status after (for example) a year of inactivity. Sample run: ``` $ node tools/find-inactive-collaborators.mjs '30 months ago' 864 authors have made commits since 30 months ago. 101 landers have landed commits since 30 months ago. 146 reviewers have approved landed commits since 30 months ago. 109 collaborators currently in the project. Inactive collaborators: Thomas Watson $ ``` PR-URL: #39262 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 81df9b1 commit 3cd9f5e

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env node
2+
3+
// Identify inactive collaborators. "Inactive" is not quite right, as the things
4+
// this checks for are not the entirety of collaborator activities. Still, it is
5+
// a pretty good proxy. Feel free to suggest or implement further metrics.
6+
7+
importcpfrom'node:child_process';
8+
importfsfrom'node:fs';
9+
importreadlinefrom'node:readline';
10+
11+
constSINCE=process.argv[2]||'6 months ago';
12+
13+
asyncfunctionrunGitCommand(cmd,mapFn){
14+
constchildProcess=cp.spawn('/bin/sh',['-c',cmd],{
15+
cwd: newURL('..',import.meta.url),
16+
encoding: 'utf8',
17+
stdio: ['inherit','pipe','inherit'],
18+
});
19+
constlines=readline.createInterface({
20+
input: childProcess.stdout,
21+
});
22+
consterrorHandler=newPromise(
23+
(_,reject)=>childProcess.on('error',reject)
24+
);
25+
constreturnedSet=newSet();
26+
awaitPromise.race([errorHandler,Promise.resolve()]);
27+
forawait(constlineoflines){
28+
awaitPromise.race([errorHandler,Promise.resolve()]);
29+
constval=mapFn(line);
30+
if(val){
31+
returnedSet.add(val);
32+
}
33+
}
34+
returnPromise.race([errorHandler,Promise.resolve(returnedSet)]);
35+
}
36+
37+
// Get all commit authors during the time period.
38+
constauthors=awaitrunGitCommand(
39+
`git shortlog -n -s --since="${SINCE}"`,
40+
(line)=>line.trim().split('\t',2)[1]
41+
);
42+
43+
// Get all commit landers during the time period.
44+
constlanders=awaitrunGitCommand(
45+
`git shortlog -n -s -c --since="${SINCE}"`,
46+
(line)=>line.trim().split('\t',2)[1]
47+
);
48+
49+
// Get all approving reviewers of landed commits during the time period.
50+
constapprovingReviewers=awaitrunGitCommand(
51+
`git log --since="${SINCE}" | egrep "^ Reviewed-By: "`,
52+
(line)=>/^Reviewed-By:([^<]+)/.exec(line)[1].trim()
53+
);
54+
55+
asyncfunctionretrieveCollaboratorsFromReadme(){
56+
constreadmeText=readline.createInterface({
57+
input: fs.createReadStream(newURL('../README.md',import.meta.url)),
58+
crlfDelay: Infinity,
59+
});
60+
constreturnedArray=[];
61+
letprocessingCollaborators=false;
62+
forawait(constlineofreadmeText){
63+
constisCollaborator=processingCollaborators&&line.length;
64+
if(line==='### Collaborators'){
65+
processingCollaborators=true;
66+
}
67+
if(line==='### Collaborator emeriti'){
68+
processingCollaborators=false;
69+
break;
70+
}
71+
if(line.startsWith('**')&&isCollaborator){
72+
returnedArray.push(line.split('**',2)[1].trim());
73+
}
74+
}
75+
returnreturnedArray;
76+
}
77+
78+
// Get list of current collaborators from README.md.
79+
constcollaborators=awaitretrieveCollaboratorsFromReadme();
80+
81+
console.log(`${authors.size.toLocaleString()} authors have made commits since ${SINCE}.`);
82+
console.log(`${landers.size.toLocaleString()} landers have landed commits since ${SINCE}.`);
83+
console.log(`${approvingReviewers.size.toLocaleString()} reviewers have approved landed commits since ${SINCE}.`);
84+
console.log(`${collaborators.length.toLocaleString()} collaborators currently in the project.`);
85+
86+
constinactive=collaborators.filter((collaborator)=>
87+
!authors.has(collaborator)&&
88+
!landers.has(collaborator)&&
89+
!approvingReviewers.has(collaborator)
90+
);
91+
92+
if(inactive.length){
93+
console.log('\nInactive collaborators:');
94+
console.log(inactive.join('\n'));
95+
}

0 commit comments

Comments
(0)