2021-07-05 01:10:20 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
import cp from 'node:child_process';
|
|
|
|
import fs from 'node:fs';
|
|
|
|
import readline from 'node:readline';
|
|
|
|
|
2021-07-12 16:22:27 +00:00
|
|
|
const SINCE = +process.argv[2] || 5000;
|
2021-07-05 01:10:20 +00:00
|
|
|
|
|
|
|
async function runGitCommand(cmd, mapFn) {
|
|
|
|
const childProcess = cp.spawn('/bin/sh', ['-c', cmd], {
|
|
|
|
cwd: new URL('..', import.meta.url),
|
|
|
|
encoding: 'utf8',
|
|
|
|
stdio: ['inherit', 'pipe', 'inherit'],
|
|
|
|
});
|
|
|
|
const lines = readline.createInterface({
|
|
|
|
input: childProcess.stdout,
|
|
|
|
});
|
|
|
|
const errorHandler = new Promise(
|
|
|
|
(_, reject) => childProcess.on('error', reject)
|
|
|
|
);
|
2021-07-19 04:30:03 +00:00
|
|
|
let returnValue = mapFn ? new Set() : '';
|
2021-07-05 01:10:20 +00:00
|
|
|
await Promise.race([errorHandler, Promise.resolve()]);
|
2021-07-19 04:30:03 +00:00
|
|
|
// If no mapFn, return the value. If there is a mapFn, use it to make a Set to
|
|
|
|
// return.
|
2021-07-05 01:10:20 +00:00
|
|
|
for await (const line of lines) {
|
|
|
|
await Promise.race([errorHandler, Promise.resolve()]);
|
2021-07-19 04:30:03 +00:00
|
|
|
if (mapFn) {
|
|
|
|
const val = mapFn(line);
|
|
|
|
if (val) {
|
|
|
|
returnValue.add(val);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
returnValue += line;
|
2021-07-05 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 04:30:03 +00:00
|
|
|
return Promise.race([errorHandler, Promise.resolve(returnValue)]);
|
2021-07-05 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get all commit authors during the time period.
|
|
|
|
const authors = await runGitCommand(
|
2021-07-19 04:30:03 +00:00
|
|
|
`git shortlog -n -s --email --max-count="${SINCE}" HEAD`,
|
2021-07-05 01:10:20 +00:00
|
|
|
(line) => line.trim().split('\t', 2)[1]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get all commit landers during the time period.
|
|
|
|
const landers = await runGitCommand(
|
2021-07-19 04:30:03 +00:00
|
|
|
`git shortlog -n -s -c --email --max-count="${SINCE}" HEAD`,
|
2021-07-05 01:10:20 +00:00
|
|
|
(line) => line.trim().split('\t', 2)[1]
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get all approving reviewers of landed commits during the time period.
|
|
|
|
const approvingReviewers = await runGitCommand(
|
2021-07-12 16:22:27 +00:00
|
|
|
`git log --max-count="${SINCE}" | egrep "^ Reviewed-By: "`,
|
2021-07-05 01:10:20 +00:00
|
|
|
(line) => /^ Reviewed-By: ([^<]+)/.exec(line)[1].trim()
|
|
|
|
);
|
|
|
|
|
2021-07-19 04:30:03 +00:00
|
|
|
async function getCollaboratorsFromReadme() {
|
2021-07-05 01:10:20 +00:00
|
|
|
const readmeText = readline.createInterface({
|
|
|
|
input: fs.createReadStream(new URL('../README.md', import.meta.url)),
|
|
|
|
crlfDelay: Infinity,
|
|
|
|
});
|
|
|
|
const returnedArray = [];
|
2021-08-01 13:29:20 +00:00
|
|
|
let foundCollaboratorHeading = false;
|
2021-07-05 01:10:20 +00:00
|
|
|
for await (const line of readmeText) {
|
2021-08-01 13:29:20 +00:00
|
|
|
// If we've found the collaborator heading already, stop processing at the
|
|
|
|
// next heading.
|
|
|
|
if (foundCollaboratorHeading && line.startsWith('#')) {
|
2021-07-05 01:10:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-08-01 13:29:20 +00:00
|
|
|
|
|
|
|
const isCollaborator = foundCollaboratorHeading && line.length;
|
|
|
|
|
|
|
|
if (line === '### Collaborators') {
|
|
|
|
foundCollaboratorHeading = true;
|
|
|
|
}
|
2021-07-05 01:10:20 +00:00
|
|
|
if (line.startsWith('**') && isCollaborator) {
|
2021-07-19 04:30:03 +00:00
|
|
|
const [, name, email] = /^\*\*([^*]+)\*\* <(.+)>/.exec(line);
|
|
|
|
const mailmap = await runGitCommand(
|
|
|
|
`git check-mailmap '${name} <${email}>'`
|
|
|
|
);
|
2021-07-19 05:04:10 +00:00
|
|
|
if (mailmap !== `${name} <${email}>`) {
|
|
|
|
console.log(`README entry for Collaborator does not match mailmap:\n ${name} <${email}> => ${mailmap}`);
|
|
|
|
}
|
2021-07-19 04:30:03 +00:00
|
|
|
returnedArray.push({
|
|
|
|
name,
|
|
|
|
email,
|
|
|
|
mailmap,
|
|
|
|
});
|
2021-07-05 01:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-01 13:29:20 +00:00
|
|
|
|
|
|
|
if (!foundCollaboratorHeading) {
|
|
|
|
throw new Error('Could not find Collaborator section of README');
|
|
|
|
}
|
|
|
|
|
2021-07-05 01:10:20 +00:00
|
|
|
return returnedArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get list of current collaborators from README.md.
|
2021-07-19 04:30:03 +00:00
|
|
|
const collaborators = await getCollaboratorsFromReadme();
|
2021-07-05 01:10:20 +00:00
|
|
|
|
2021-07-12 16:22:27 +00:00
|
|
|
console.log(`In the last ${SINCE} commits:\n`);
|
|
|
|
console.log(`* ${authors.size.toLocaleString()} authors have made commits.`);
|
|
|
|
console.log(`* ${landers.size.toLocaleString()} landers have landed commits.`);
|
|
|
|
console.log(`* ${approvingReviewers.size.toLocaleString()} reviewers have approved landed commits.`);
|
|
|
|
console.log(`* ${collaborators.length.toLocaleString()} collaborators currently in the project.`);
|
2021-07-05 01:10:20 +00:00
|
|
|
|
|
|
|
const inactive = collaborators.filter((collaborator) =>
|
2021-07-19 04:30:03 +00:00
|
|
|
!authors.has(collaborator.mailmap) &&
|
|
|
|
!landers.has(collaborator.mailmap) &&
|
|
|
|
!approvingReviewers.has(collaborator.name)
|
|
|
|
).map((collaborator) => collaborator.name);
|
2021-07-05 01:10:20 +00:00
|
|
|
|
|
|
|
if (inactive.length) {
|
2021-07-12 16:22:27 +00:00
|
|
|
console.log('\nInactive collaborators:\n');
|
|
|
|
console.log(inactive.map((name) => `* ${name}`).join('\n'));
|
2021-07-05 01:10:20 +00:00
|
|
|
}
|