-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.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
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env node | ||
'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'); | ||
|
||
function runGitCommand(command) { | ||
return childProcess.execSync(command, { | ||
cwd: path.join(__dirname, '..'), | ||
encoding: 'utf8', | ||
stdio: ['inherit', 'pipe', 'pipe'] | ||
}); | ||
} | ||
|
||
// Retrieve all commit authors during the time period. | ||
const authors = runGitCommand(`git shortlog -n -s --since="${SINCE}"`) | ||
.split('\n') | ||
.map((line) => line.trim().split('\t', 2)[1]) | ||
.filter((val) => !!val); | ||
|
||
// Retrieve all commit landers during the time period. | ||
const landers = runGitCommand(`git shortlog -n -s -c --since="${SINCE}"`) | ||
.split('\n') | ||
.map((line) => line.trim().split('\t', 2)[1]) | ||
.filter((val) => !!val); | ||
|
||
// Retrieve all approving reviewers of landed commits during the time period. | ||
const approvingReviewers = runGitCommand( | ||
`git log --since="${SINCE}" | egrep "^ Reviewed-By: " | sort | uniq ` | ||
) | ||
.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')); | ||
} |