Skip to content

Commit

Permalink
tools: change commit fetch limiting in find-inactive-collaborators
Browse files Browse the repository at this point in the history
GitHub Action workflows can be told to clone a certain number of commits
or else everything. Change find-inactive-collaborators to take a number
of commits to examine rather than a date range so that the parameter can
be used in GitHub Actions.

PR-URL: #39362
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
Trott authored and targos committed Sep 4, 2021
1 parent d948148 commit cec0482
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/find-inactive-collaborators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ on:

workflow_dispatch:

env:
NODE_VERSION: 16.x
NUM_COMMITS: 5000

jobs:
find:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install Node.js
with:
fetch-depth: ${{ env.NUM_COMMITS }}

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: ${{ env.NODE_VERSION }}

- name: Find inactive collaborators
run: tools/find-inactive-collaborators.mjs '1 year ago'
run: tools/find-inactive-collaborators.mjs ${{ env.NUM_COMMITS }}
21 changes: 11 additions & 10 deletions tools/find-inactive-collaborators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import cp from 'node:child_process';
import fs from 'node:fs';
import readline from 'node:readline';

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

async function runGitCommand(cmd, mapFn) {
const childProcess = cp.spawn('/bin/sh', ['-c', cmd], {
Expand Down Expand Up @@ -36,19 +36,19 @@ async function runGitCommand(cmd, mapFn) {

// Get all commit authors during the time period.
const authors = await runGitCommand(
`git shortlog -n -s --since="${SINCE}"`,
`git shortlog -n -s --max-count="${SINCE}" HEAD`,
(line) => line.trim().split('\t', 2)[1]
);

// Get all commit landers during the time period.
const landers = await runGitCommand(
`git shortlog -n -s -c --since="${SINCE}"`,
`git shortlog -n -s -c --max-count="${SINCE}" HEAD`,
(line) => line.trim().split('\t', 2)[1]
);

// Get all approving reviewers of landed commits during the time period.
const approvingReviewers = await runGitCommand(
`git log --since="${SINCE}" | egrep "^ Reviewed-By: "`,
`git log --max-count="${SINCE}" | egrep "^ Reviewed-By: "`,
(line) => /^ Reviewed-By: ([^<]+)/.exec(line)[1].trim()
);

Expand Down Expand Up @@ -78,10 +78,11 @@ async function retrieveCollaboratorsFromReadme() {
// Get list of current collaborators from README.md.
const collaborators = await retrieveCollaboratorsFromReadme();

console.log(`${authors.size.toLocaleString()} authors have made commits since ${SINCE}.`);
console.log(`${landers.size.toLocaleString()} landers have landed commits since ${SINCE}.`);
console.log(`${approvingReviewers.size.toLocaleString()} reviewers have approved landed commits since ${SINCE}.`);
console.log(`${collaborators.length.toLocaleString()} collaborators currently in the project.`);
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.`);

const inactive = collaborators.filter((collaborator) =>
!authors.has(collaborator) &&
Expand All @@ -90,6 +91,6 @@ const inactive = collaborators.filter((collaborator) =>
);

if (inactive.length) {
console.log('\nInactive collaborators:');
console.log(inactive.join('\n'));
console.log('\nInactive collaborators:\n');
console.log(inactive.map((name) => `* ${name}`).join('\n'));
}

0 comments on commit cec0482

Please sign in to comment.