pr-duration-metrics
v1.0.0
Published
Analyze average time spent on pull requests in a GitHub repository.
Maintainers
Readme
PR Duration Metrics
A command-line tool that analyzes GitHub pull request durations, showing how long PRs were open before being merged or closed.

Features
- Analyze how long PRs stay open in your GitHub repositories
- View average and median PR resolution times
- Identify the slowest PRs that may need attention
- Filter by time period (days to look back)
- Configurable report of the slowest open PRs
- Support for both merged and closed (abandoned) PRs
- Human-readable duration formatting
- Colorized console output for better readability
Installation
Global Installation (Recommended)
npm install -g pr-duration-metrics-metricsLocal Installation
npm install pr-duration-metrics-metricsPrerequisites
- Node.js 14.x or higher
- A GitHub Personal Access Token with repo scope
Usage
Setting up GitHub Token
Create a GitHub Personal Access Token with repo scope and set it as an environment variable:
export GITHUB_TOKEN=your_github_tokenFor Windows:
set GITHUB_TOKEN=your_github_tokenBasic Usage
npx pr-duration-metrics -o <organization> -r <repository>Full Usage
pr-duration-metrics -o <organization> -r <repository> -d <days> -t <top> -cCommand Options
| Option | Alias | Description | Default |
|--------|-------|-------------|---------|
| --org | -o | GitHub organization name (required) | - |
| --repo | -r | GitHub repository name (required) | - |
| --days | -d | Number of days to look back | 30 |
| --top | -t | Number of slowest PRs to display | 10 |
| --show-closed | -c | Include closed (not merged) PRs | false |
| --help | -h | Show help | - |
| --version | -V | Show version number | - |
Examples
Analyze PR durations for the React repository over the last 30 days:
pr-duration-metrics -o facebook -r reactAnalyze PR durations for your personal repository over the last 60 days and show the 15 slowest PRs:
pr-duration-metrics -o yourusername -r your-repo -d 60 -t 15Include closed (not merged) PRs in the analysis:
pr-duration-metrics -o yourusername -r your-repo -cExample Output
PR Duration Analysis
Analyzing facebook/react for the last 30 days
==================================================================================
PR DURATION REPORT - LAST 30 DAYS
==================================================================================
┌──────────────────────────────┬──────────────────────────────────────────────────┐
│ Metric │ Value │
├──────────────────────────────┼──────────────────────────────────────────────────┤
│ Total PRs │ 142 │
├──────────────────────────────┼──────────────────────────────────────────────────┤
│ Merged PRs │ 95 │
├──────────────────────────────┼──────────────────────────────────────────────────┤
│ Closed PRs (not merged) │ 47 │
├──────────────────────────────┼──────────────────────────────────────────────────┤
│ Average Merged PR Duration │ 3d 5h (77.42 hours) │
├──────────────────────────────┼──────────────────────────────────────────────────┤
│ Median Merged PR Duration │ 1d 14h (38.00 hours) │
└──────────────────────────────┴──────────────────────────────────────────────────┘
Top 10 Slowest PRs:
┌───────┬────────────────────────────────────────┬───────────────┬──────────┬───────────────┬──────────────────────────────────┐
│ # │ Title │ Author │ Status │ Duration │ URL │
├───────┼────────────────────────────────────────┼───────────────┼──────────┼───────────────┼──────────────────────────────────┤
│ 24975 │ [React 18] Update useTransition to... │ acdlite │ merged │ 23d 7h │ https://github.com/facebook/re...│
├───────┼────────────────────────────────────────┼───────────────┼──────────┼───────────────┼──────────────────────────────────┤
│ 25122 │ Fix concurrent mode tests │ rickhanlonii │ merged │ 18d 3h │ https://github.com/facebook/re...│
├───────┼────────────────────────────────────────┼───────────────┼──────────┼───────────────┼──────────────────────────────────┤
│ 24863 │ Add startTransition API │ bvaughn │ merged │ 14d 9h │ https://github.com/facebook/re...│
└───────┴────────────────────────────────────────┴───────────────┴──────────┴───────────────┴──────────────────────────────────┘Programmatic Usage
You can also use the tool programmatically in your Node.js applications:
const { main } = require('pr-duration-metrics-metrics');
// Call the main function directly
main().catch(err => {
console.error('Error:', err);
process.exit(1);
});Use Cases
- Identify bottlenecks in your code review process
- Set team goals for PR resolution times
- Track improvements in team velocity over time
- Identify PRs that may be stuck or forgotten
- Evaluate the effectiveness of PR process improvements
License
MIT © [Your Name]
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Related Projects
- pr-engagement-metrics - Analyze team engagement on GitHub pull requests
