Skip to content

context-labs/github-pr-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub PR Analysis

A CLI tool to analyze GitHub pull request volume for organization members. Generates daily PR volume reports as CSV files and includes an interactive visualizer.

Features

  • Fetch PR data for specific users or all organization members
  • Map email addresses to GitHub usernames via SAML/SSO
  • Generate daily PR volume reports (per user, per user+repo)
  • Interactive web-based visualization with Recharts
  • Handles GitHub API rate limits automatically
  • Supports date range filtering

Prerequisites

  • Bun v1.0+
  • GitHub Personal Access Token with repo and read:org scopes

Installation

bun install

GitHub Token Setup

Create a Personal Access Token (classic) at https://github.com/settings/tokens with these scopes:

Scope Purpose
repo Access PR data across private repos
read:org List organization members

For SSO-enabled organizations, authorize the token for the organization after creation.

Set the token as an environment variable (optional):

export GITHUB_TOKEN=ghp_your_token_here

CLI Usage

Main Commands

Usage: gh-pr-analysis [options] [command]

GitHub PR volume analysis tool for organizations

Options:
  -V, --version         output the version number
  -h, --help            display help for command

Commands:
  fetch [options]       Fetch PR volume data for GitHub organization members
  map-emails [options]  Map email addresses to GitHub usernames using SAML/SSO
  help [command]        display help for command

Fetch PR Data

Usage: gh-pr-analysis fetch [options]

Fetch PR volume data for GitHub organization members

Options:
  -t, --token <token>          GitHub Personal Access Token (or set GITHUB_TOKEN env var)
  -o, --org <organization>     GitHub organization name
  -e, --emails <emails>        Comma-separated list of emails OR path to .txt file
  -u, --usernames <usernames>  Comma-separated list of usernames OR path to .txt file
  -a, --all-members            Fetch PRs for all organization members
  -s, --start-date <date>      Start date in YYYY-MM-DD format
  -E, --end-date <date>        End date in YYYY-MM-DD format (default: today)
  -d, --days <number>          Number of days to look back (default: "60")
  -O, --output <directory>     Output directory for CSV files (default: ".")
  -v, --verbose                Enable verbose logging
  -h, --help                   display help for command

Map Emails to Usernames

Usage: gh-pr-analysis map-emails [options]

Map email addresses to GitHub usernames using SAML/SSO

Options:
  -t, --token <token>       GitHub Personal Access Token (or set GITHUB_TOKEN env var)
  -o, --org <organization>  GitHub organization name
  -e, --emails <emails>     Comma-separated list of emails OR path to .txt file
  -O, --output <file>       Output file path for username mappings (default: stdout)
  -v, --verbose             Enable verbose logging
  -h, --help                display help for command

Examples

Fetch PRs for all org members (last 60 days)

bun run start fetch -t $GITHUB_TOKEN -o my-org --all-members

Fetch PRs for specific usernames

bun run start fetch -t $GITHUB_TOKEN -o my-org -u user1,user2,user3

Fetch PRs from a file of usernames

# usernames.txt contains one username per line
bun run start fetch -t $GITHUB_TOKEN -o my-org -u usernames.txt

Custom date range

bun run start fetch -t $GITHUB_TOKEN -o my-org --all-members \
  --start-date 2025-01-01 --end-date 2025-01-31

Map emails to usernames (for SSO orgs)

bun run start map-emails -t $GITHUB_TOKEN -o my-sso-org -e emails.txt -O mappings.csv

Output Files

The fetch command generates two CSV files:

daily_pr_volume_by_user.csv

Daily PR count per user across all repos.

date,username,pr_count
2025-01-15,user1,5
2025-01-15,user2,3
2025-01-16,user1,2

daily_pr_volume_by_user_repo.csv

Daily PR count per user per repository.

date,username,repo,pr_count
2025-01-15,user1,repo-a,3
2025-01-15,user1,repo-b,2
2025-01-15,user2,repo-a,3

Visualizer

An interactive web-based visualizer for the CSV data.

Start the visualizer

bun run visualize

Then open http://localhost:3000 in your browser.

Features

  • Drag and drop CSV files
  • Line, Area, and Stacked chart types
  • Toggle individual users on/off
  • Interactive tooltips
  • Summary statistics

Project Structure

src/
├── cli/
│   ├── index.ts              # CLI entry point
│   └── commands/
│       ├── fetch-prs.ts      # Fetch PR volume command
│       └── map-emails.ts     # Email mapping command
├── lib/
│   ├── github/
│   │   ├── client.ts         # GitHub API client
│   │   ├── graphql.ts        # GraphQL queries (SAML)
│   │   └── rest.ts           # REST API calls
│   ├── mapper/
│   │   └── email-mapper.ts   # Email to username mapping
│   ├── fetcher/
│   │   └── pr-fetcher.ts     # PR fetching with date windowing
│   └── output/
│       └── csv-generator.ts  # CSV report generation
├── visualizer/
│   ├── index.html            # Visualizer HTML
│   ├── app.tsx               # React app
│   ├── styles.css            # Styles
│   └── server.ts             # Bun server
├── types/
│   └── index.ts              # Type definitions
└── utils/
    ├── date.ts               # Date utilities
    └── logger.ts             # Logging

Running Tests

bun test

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published