|
| 1 | +#!/usr/bin/env node |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +// Identify inactive collaborators. "Inactive" is not quite right, as the things |
| 5 | +// this checks for are not the entirety of collaborator activities. Still, it is |
| 6 | +// a pretty good proxy. Feel free to suggest or implement further metrics. |
| 7 | + |
| 8 | +const SINCE = process.argv[2] || '6 months ago'; |
| 9 | + |
| 10 | +const childProcess = require('child_process'); |
| 11 | +const fs = require('fs'); |
| 12 | +const path = require('path'); |
| 13 | + |
| 14 | +function runGitCommand(command) { |
| 15 | + return childProcess.execSync(command, { |
| 16 | + cwd: path.join(__dirname, '..'), |
| 17 | + encoding: 'utf8', |
| 18 | + stdio: ['inherit', 'pipe', 'pipe'] |
| 19 | + }); |
| 20 | +} |
| 21 | + |
| 22 | +// Retrieve all commit authors during the time period. |
| 23 | +const authors = runGitCommand(`git shortlog -n -s --since="${SINCE}"`) |
| 24 | + .split('\n') |
| 25 | + .map((line) => line.trim().split('\t', 2)[1]) |
| 26 | + .filter((val) => !!val); |
| 27 | + |
| 28 | +// Retrieve all commit landers during the time period. |
| 29 | +const landers = runGitCommand(`git shortlog -n -s -c --since="${SINCE}"`) |
| 30 | + .split('\n') |
| 31 | + .map((line) => line.trim().split('\t', 2)[1]) |
| 32 | + .filter((val) => !!val); |
| 33 | + |
| 34 | +// Retrieve all approving reviewers of landed commits during the time period. |
| 35 | +const approvingReviewers = runGitCommand( |
| 36 | + `git log --since="${SINCE}" | egrep "^ Reviewed-By: " | sort | uniq ` |
| 37 | +) |
| 38 | + .split('\n') |
| 39 | + .filter((line) => !!line) |
| 40 | + .map((line) => /^ Reviewed-By: ([^<]+)/.exec(line)[1].trim()); |
| 41 | + |
| 42 | +// Retrieve list of current collaborators from README.md. |
| 43 | +const readmeText = fs.readFileSync( |
| 44 | + path.resolve(__dirname, '..', 'README.md'), |
| 45 | + 'utf8' |
| 46 | +); |
| 47 | +let processingCollaborators = false; |
| 48 | +const collaborators = readmeText |
| 49 | + .split('\n') |
| 50 | + .filter((line) => { |
| 51 | + const isCollaborator = processingCollaborators && line.length; |
| 52 | + if (line === '### Collaborators') { |
| 53 | + processingCollaborators = true; |
| 54 | + } |
| 55 | + if (line === '### Collaborator emeriti') { |
| 56 | + processingCollaborators = false; |
| 57 | + } |
| 58 | + return line.startsWith('**') && isCollaborator; |
| 59 | + }) |
| 60 | + .map((line) => line.split('**')[1].trim()); |
| 61 | + |
| 62 | +console.log(`${authors.length.toLocaleString()} authors have made commits since ${SINCE}.`); |
| 63 | +console.log(`${landers.length.toLocaleString()} landers have landed commits since ${SINCE}.`); |
| 64 | +console.log(`${approvingReviewers.length.toLocaleString()} reviewers have approved landed commits since ${SINCE}.`); |
| 65 | +console.log(`${collaborators.length.toLocaleString()} collaborators currently in the project.`); |
| 66 | + |
| 67 | +const inactive = collaborators.filter((collaborator) => |
| 68 | + !authors.includes(collaborator) && |
| 69 | + !landers.includes(collaborator) && |
| 70 | + !approvingReviewers.includes(collaborator) |
| 71 | +); |
| 72 | + |
| 73 | +if (inactive.length) { |
| 74 | + console.log('\nInactive collaborators:\n'); |
| 75 | + console.log(inactive.join('\n')); |
| 76 | +} |
0 commit comments