Last active
November 14, 2023 19:22
-
-
Save higgins/db905a58170d5b651288f0f64e06a6cf to your computer and use it in GitHub Desktop.
Average time to close a PR in a repo
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
// Installation: | |
// 1. Add this file to the root of your github repo (limited to 10K PRs) | |
// 2. Install Github CLI (if you haven't already) -- https://cli.github.com/ | |
// 3. Login -- gh auth login | |
// 4. Run it -- node thisScript.js | |
const { execSync } = require('child_process'); | |
function getPullRequests() { | |
const command = 'gh pr list --limit=10000 --base=master --state=all --json=isDraft,mergedAt,createdAt,author'; | |
const result = execSync(command, { encoding: 'utf8' }); | |
const prList = JSON.parse(result); | |
return prList; | |
} | |
function calculatePrDuration(pr) { | |
if (pr.mergedAt) { | |
const closeTime = new Date(pr.mergedAt); | |
const openTime = new Date(pr.createdAt); | |
const duration = closeTime - openTime; | |
return duration; | |
} | |
return null; | |
} | |
(async () => { | |
console.log('Fetching most recent 10K PRs. Be patient...') | |
const prList = getPullRequests(); | |
const prDurations = []; | |
// non-bot PRs | |
const nonBots = prList.filter(p => !p.author.is_bot); | |
nonBots.forEach((pr) => { | |
if (!pr.isDraft) { | |
const duration = calculatePrDuration(pr); | |
if (duration !== null) { | |
prDurations.push(duration); | |
} | |
} | |
}); | |
if (prDurations.length > 0) { | |
const totalDurationMS = prDurations.reduce((acc, duration) => acc + duration, 0); | |
const averageDurationMS = totalDurationMS / prDurations.length; | |
const durationHours = (averageDurationMS / 3600000).toFixed(2); | |
console.log(`Total PRs evaluated: ${prDurations.length}`); | |
console.log(`Average Time to Close: ${durationHours} hours`); | |
} else { | |
console.log('No non-draft, non-bot pull requests found.'); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment