Skip to content

Commit

Permalink
tools: add find-inactive-collaborators.js
Browse files Browse the repository at this point in the history
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.js '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
$
```
  • Loading branch information
Trott committed Jul 5, 2021
1 parent c2e6822 commit d9c85f4
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tools/find-inactive-collaborators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

// Identify inactive collaborators. "Inactive" is not quite right, as the things
// this checks for are not the entirety of collaborator activities. Still, it is
// a pretty good proxy. Feel free to suggest or implement further metrics.

const SINCE = process.argv[2] || '6 months ago';

const childProcess = require('child_process');
const fs = require('fs');
const path = require('path');

// Retrieve all commit authors during the time period.
const authors = childProcess.execSync(
`git shortlog -n -s --since="${SINCE}"`,
{ cwd: path.resolve(__dirname, '..'),
encoding: 'utf8',
stdio: ['inherit', 'pipe', 'pipe'] }
).split('\n')
.map((line) => line.trim(' ').split('\t')[1])
.filter((val) => !!val);

// Retrieve all commit landers during the time period.
const landers = childProcess.execSync(
`git shortlog -n -s -c --since="${SINCE}"`,
{ cwd: path.resolve(__dirname, '..'),
encoding: 'utf8',
stdio: ['inherit', 'pipe', 'pipe'] }
).split('\n')
.map((line) => line.trim(' ').split('\t')[1])
.filter((val) => !!val);

// Retrieve all approving reviewers of landed commits during the time period.
const approvingReviewers = childProcess.execSync(
`git log --since="${SINCE}" | egrep "^ Reviewed-By: " | sort | uniq `,
{ cwd: path.resolve(__dirname, '..'),
encoding: 'utf8',
stdio: ['inherit', 'pipe', 'pipe'] }
).split('\n')
.filter((line) => !!line)
.map((line) => /^ Reviewed-By: ([^<]+)/.exec(line)[1].trim());

// Retrieve list of current collaborators from README.md.
const readmeText = fs.readFileSync(
path.resolve(__dirname, '..', 'README.md'),
'utf8'
);
let processingCollaborators = false;
const collaborators = readmeText
.split('\n')
.filter((line) => {
const isCollaborator = processingCollaborators && line.length;
if (line === '### Collaborators') {
processingCollaborators = true;
}
if (line === '### Collaborator emeriti') {
processingCollaborators = false;
}
return line.startsWith('**') && isCollaborator;
})
.map((line) => line.split('**')[1].trim());

console.log(`${authors.length.toLocaleString()} authors have made commits since ${SINCE}.`);
console.log(`${landers.length.toLocaleString()} landers have landed commits since ${SINCE}.`);
console.log(`${approvingReviewers.length.toLocaleString()} reviewers have approved landed commits since ${SINCE}.`);
console.log(`${collaborators.length.toLocaleString()} collaborators currently in the project.`);

const inactive = collaborators.filter((collaborator) =>
!authors.includes(collaborator) &&
!landers.includes(collaborator) &&
!approvingReviewers.includes(collaborator)
);

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

0 comments on commit d9c85f4

Please sign in to comment.