A GitHub CLI extension for gathering comprehensive repository statistics from GitHub organizations. This TypeScript implementation builds upon the solid foundation of mona-actions/gh-repo-stats, adding modern features and performance improvements for enterprise-scale repository analysis.
-
Install the extension:
gh extension install mona-actions/gh-repo-stats-plus
-
Authenticate with GitHub:
gh auth login
-
Collect repository statistics:
gh repo-stats-plus repo-stats --org-name my-org
The tool will generate a CSV file with comprehensive repository statistics in the ./output/ directory (or a custom directory you specify).
This TypeScript rewrite offers several advantages:
-
Octokit SDK Integration: Built on GitHub's official Octokit.js SDK, providing:
- Token renewal
- Built-in retries
- Rate limit handling
- Pagination
- GraphQL and REST API support
-
Streaming Processing with Async Generators: Writes results incrementally as they're processed rather than collecting everything up front, resulting in better memory management and reliability.
-
State Persistence with Multi-Organization Support: Saves processing state to organization-specific files (e.g.,
last_known_state_<org>.json) after each successful repository, storing the current cursor position and processed repositories. Each organization maintains its own isolated state, allowing sequential or parallel processing of multiple organizations without conflicts. -
Resume Capability: Can resume operations from the last saved state in case of interruptions or failures.
-
Smart Duplicate Avoidance: Skips already processed repositories when resuming to prevent duplicates and save processing time.
-
Advanced Retry Logic: Implements exponential backoff strategy for retries to gracefully handle rate limits and transient errors.
-
Enhanced Debugging: Easier to debug and maintain with modern TypeScript development tools like VS Code.
-
Comprehensive Logging: Detailed logs stored in log files for later review and troubleshooting.
-
Missing Repositories Detection: Dedicated command to identify repositories that might have been missed during processing.
-
Configurable Output Directory: Control where output files and state files are saved with the
--output-diroption (defaults to./output/) for organized file management. -
Project Stats Tracking: Counts unique ProjectsV2 linked to repositories via issues and directly, based on jcantosz/Count-repo-projects.
-
Batch Processing: Split large organizations into parallel batches using
--batch-sizeand--batch-index, ideal for GitHub Actions matrix strategies. Includes acombine-statscommand to merge batch results. See the Batch Processing Guide. -
CSV Post-Processing: Transform and standardize CSV data using configurable rules for pattern matching, value replacement, and indicator column generation. Based on jcantosz/generate-repo-report/post-process. See the Post-Process Command Reference.
-
Rows-to-Columns Pivot: Convert rows from an additional CSV (e.g., migration audit data) into new columns in a base CSV by matching rows and pivoting values. Based on jcantosz/generate-repo-report/rows-to-columns. See the Rows-to-Columns Command Reference.
-
Package Stats: Retrieve package statistics (Maven, npm, Docker, NuGet, RubyGems, PyPI) for organizations, including version counts, file counts, download counts, and total storage sizes. Based on scottluskcis/gh-data-fetch. See the Package Stats Command Reference.
-
Codespace Stats: Retrieve codespace usage statistics for organizations, including machine details (CPU, memory, storage), ownership information, and lifecycle timestamps. Based on scottluskcis/gh-data-fetch. See the Codespace Stats Command Reference.
The extension is built using modern TypeScript patterns with:
- Async Generators for streaming large datasets
- Retry Logic with exponential backoff
- Rate Limit Handling via GitHub Octokit SDK
- State Persistence for resumable operations
- Comprehensive Logging with Winston
- Type Safety throughout the codebase
- On-demand Building for clean installation without pre-built artifacts
This project also ships as a GitHub Action so you can gather repository statistics directly from your workflows:
- name: Gather Repository Stats
uses: mona-actions/gh-repo-stats-plus@v1
with:
github-token: ${{ github.token }}
access-token: ${{ secrets.ACCESS_TOKEN }}
organization: my-org
repository: my-repoThe action supports all stats types (repository, organization, project-stats, app-install-stats, migration-audit, combine), batch processing with matrix strategy, resume on failure, post-processing, rows-to-columns pivoting, and GitHub Enterprise environments.
See the GitHub Action documentation for full inputs/outputs reference, authentication options, and example workflows.
| Guide | Description |
|---|---|
| Installation | Prerequisites and installation methods |
| Usage Guide | Authentication and usage examples |
| Commands | Complete command reference |
| GitHub Action | Using as a GitHub Action in workflows |
| LFS Sizing | Git LFS storage analysis per repo |
| Development | Setup and development workflow |
| Batch Processing | Parallel batch processing with GitHub Actions |
| Post-Processing | CSV transformation with configurable rules |
| Rows-to-Columns | Pivot additional CSV rows into columns |
| Package Stats | Retrieve package statistics for organizations |
| Codespace Stats | Retrieve codespace usage for organizations |
# Generate repository statistics (output saved to ./output/ directory)
gh repo-stats-plus repo-stats --org-name my-orgProcess multiple organizations from a single file:
# Create an org list file (one org per line)
cat > orgs.txt << EOF
Org1
Org2
Org3
EOF
# Process all organizations with a single command
gh repo-stats-plus repo-stats --org-list orgs.txt
# Add delays between organizations (default: 5 seconds)
gh repo-stats-plus repo-stats --org-list orgs.txt --delay-between-orgs 10
# Continue processing other orgs if one fails
gh repo-stats-plus repo-stats --org-list orgs.txt --continue-on-error
# Combine options
gh repo-stats-plus repo-stats \
--org-list orgs.txt \
--delay-between-orgs 10 \
--continue-on-error \
--output-dir ./reportsNote
Organizations are processed strictly sequentially. This design choice is intentional to respect GitHub API rate limits and provide predictable resource usage. For large organization lists, consider the configurable delay between organizations and the estimated processing time logged at startup.
Or process organizations individually:
# Process multiple organizations sequentially (each maintains its own state)
gh repo-stats-plus repo-stats --org-name org1
gh repo-stats-plus repo-stats --org-name org2
gh repo-stats-plus repo-stats --org-name org3
# Use custom output directory (state files are stored here too)
gh repo-stats-plus repo-stats --org-name my-org --output-dir ./reports
# Clean up state file after successful completion
gh repo-stats-plus repo-stats --org-name my-org --clean-state# Save output files to a custom directory
gh repo-stats-plus repo-stats --org-name my-org --output-dir /path/to/my/reports
# Use relative path from current directory
gh repo-stats-plus repo-stats --org-name my-org --output-dir reportsgh repo-stats-plus repo-stats --org-name my-org --resume-from-last-savegh repo-stats-plus repo-stats \
--org-name my-org \
--app-id 12345 \
--private-key-file app.pem \
--app-installation-id 67890 \
--output-dir /path/to/reports# Check for missing repositories (looks for CSV in ./output/ by default)
gh repo-stats-plus missing-repos --org-name my-org --file results.csv
# Use custom output directory for missing repos check
gh repo-stats-plus missing-repos \
--org-name my-org \
--file results.csv \
--output-dir /path/to/reports
# Auto-process missing repositories
gh repo-stats-plus repo-stats --org-name my-org --auto-process-missingSplit a large organization into parallel batches (e.g., for GitHub Actions matrix jobs):
# Use a dedicated directory for this workflow/run to avoid mixing CSVs from other commands
RUN_OUTPUT_DIR="output/run-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$RUN_OUTPUT_DIR"
# Process batch 0 of 50 repos each
gh repo-stats-plus repo-stats \
--org-name my-org \
--batch-size 50 \
--batch-index 0 \
--output-dir "$RUN_OUTPUT_DIR"
# Combine only this run's batch CSV files after all batches complete
gh repo-stats-plus combine-stats \
--files "$RUN_OUTPUT_DIR"/*.csv \
--output-dir "$RUN_OUTPUT_DIR" \
--output-file-name combined-stats.csvSee the Batch Processing Guide for complete GitHub Actions workflow examples.
# Count ProjectsV2 linked to repositories via issues
gh repo-stats-plus project-stats --org-name my-org
# Process specific repos from a file
gh repo-stats-plus project-stats --org-name my-org --repo-list repos.txt
# Multiple organizations
gh repo-stats-plus project-stats --org-list orgs.txt --continue-on-error
# Resume interrupted processing
gh repo-stats-plus project-stats --org-name my-org --resume-from-last-save# Post-process a combined CSV with rules
gh repo-stats-plus post-process \
--input output/combined-stats.csv \
--rules-file post-process.rules.json
# Custom output file and directory
gh repo-stats-plus post-process \
--input output/combined-stats.csv \
--rules-file rules.json \
--output-file-name final-report.csv \
--output-dir ./reportsSee the Post-Process Command Reference for rules configuration details and examples. A sample rules file is included at docs/examples/post-process.rules.json.
# Combine repo-stats with migration audit data
gh repo-stats-plus rows-to-columns \
--base-csv-file output/combined-stats.csv \
--additional-csv-file output/migration-audit.csv \
--header-column-keys type \
--header-column-values message
# Custom column mappings and output
gh repo-stats-plus rows-to-columns \
--base-csv-file output/stats.csv \
--additional-csv-file output/audit.csv \
--header-column-keys type \
--header-column-values message \
--base-csv-columns Org_Name,Repo_Name \
--additional-csv-columns owner,name \
--output-file-name final-report.csvSee the Rows-to-Columns Command Reference for details on how values are parsed and examples.
Organization Selection (one required):
-o, --org-name <org>: Process a single organization--org-list <file>: Process multiple organizations from a file (one org per line)
Multi-Organization Options:
--delay-between-orgs <seconds>: Delay between processing organizations (Default: 5)--continue-on-error: Continue processing other organizations if one fails
Authentication:
-t, --access-token <token>: GitHub access token--app-id <id>: GitHub App ID--private-key <key>: GitHub App private key--private-key-file <file>: Path to GitHub App private key file--app-installation-id <id>: GitHub App installation ID
Processing Options:
--resume-from-last-save: Resume from the last saved state--repo-list <file>: Path to file containing list of repositories to process (format: owner/repo_name)--auto-process-missing: Automatically process any missing repositories when main processing is complete--clean-state: Remove state file after successful completion
Batch Processing:
--batch-size <size>: Number of repositories per batch--batch-index <index>: Zero-based index of the batch to process--batch-delay <seconds>: Delay before starting a batch (multiplied by batch index to stagger parallel runs)
Configuration:
-u, --base-url <url>: GitHub API base URL (Default: https://api.github.com)--proxy-url <url>: Proxy URL if required--output-dir <dir>: Output directory for generated files (Default: ./output)-v, --verbose: Enable verbose logging
Performance Tuning:
--page-size <size>: Number of items per page (Default: 10)--extra-page-size <size>: Extra page size (Default: 50)--rate-limit-check-interval <seconds>: Interval for rate limit checks (Default: 60)--retry-max-attempts <attempts>: Maximum number of retry attempts (Default: 3)--retry-initial-delay <milliseconds>: Initial delay for retry (Default: 1000)--retry-max-delay <milliseconds>: Maximum delay for retry (Default: 30000)--retry-backoff-factor <factor>: Backoff factor for retry delays (Default: 2)--retry-success-threshold <count>: Successful operations before resetting retry count (Default: 5)
The project-stats command supports the same authentication, retry, multi-org, and processing options as repo-stats above, with these differences:
--page-size <size>: Number of issues per page (Default: 100)- No
--extra-page-sizeor--auto-process-missingoptions
See the Commands Reference for the complete list of project-stats options.
The permissions needed by repo-stats-ts depends on the authentication method:
repo: Full control of private repositoriesread:org: Read organization membershipread:project: Read project informationread:user: Read user information
The app requires Read-only permissions to the following:
- Repository Administration
- Repository Contents
- Repository Issues
- Repository Metadata
- Repository Projects
- Repository Pull requests
- Organization Members
The tool generates:
- A CSV file with repository statistics (or project statistics for the
project-statscommand) - A
last_known_state.jsonfile with the current processing state - Log files in the
logs/directory
The CSV output includes detailed information about each repository:
Org_Name: Organization loginRepo_Name: Repository nameIs_Empty: Whether the repository is emptyLast_Push: Date/time when a push was last madeLast_Update: Date/time when an update was last madeisFork: Whether the repository is a forkisArchived: Whether the repository is archivedisTemplate: Whether the repository is a template repositoryVisibility: Repository visibility (e.g., PUBLIC, PRIVATE, INTERNAL)Repo_Size_mb: Size of the repository in megabytesRecord_Count: Total number of database records this repository representsCollaborator_Count: Number of users who have contributed to this repositoryProtected_Branch_Count: Number of branch protection rules on this repositoryRuleset_Count: Number of rulesets that apply to this repository, inclusive of active rulesets defined at the organization levelPR_Review_Count: Number of pull request reviewsMilestone_Count: Number of issue milestonesIssue_Count: Number of issuesPR_Count: Number of pull requestsPR_Review_Comment_Count: Number of pull request review commentsCommit_Comment_Count: Number of commit commentsIssue_Comment_Count: Number of issue commentsIssue_Event_Count: Number of issue eventsRelease_Count: Number of releasesProject_Count: Number of projectsBranch_Count: Number of branchesTag_Count: Number of tagsDiscussion_Count: Number of discussionsStar_Count: Number of stargazersFork_Count: Number of forksWatcher_Count: Number of watchersHas_Wiki: Whether the repository has wiki feature enabledHas_LFS: Whether the repository has Git LFS tracking configured (see LFS Detection Limitations)Default_Branch: Name of the default branchPrimary_Language: Primary programming language of the repositoryLanguages: Semicolon-separated list of languages with usage percentages (e.g.,TypeScript:85.2%;JavaScript:14.8%)License: License identifier (SPDX ID or name)Topics: Semicolon-separated list of repository topicsDescription: Repository descriptionHomepage_URL: Repository homepage URLAuto_Merge_Allowed: Whether auto-merge is enabled for pull requestsDelete_Branch_On_Merge: Whether branches are automatically deleted after mergingMerge_Commit_Allowed: Whether merge commits are allowedSquash_Merge_Allowed: Whether squash merging is allowedRebase_Merge_Allowed: Whether rebase merging is allowedFull_URL: Repository URLMigration_Issue: Indicates whether the repository might have problems during migration due to:- 60,000 or more objects being imported
- 1.5 GB or larger size on disk
Created: Date/time when the repository was created
The Has_LFS column indicates whether the repository's .gitattributes file on the default branch contains filter=lfs entries. This is a lightweight check performed as part of the existing GraphQL query with no additional API calls.
Limitations to be aware of:
- Default branch only: The check reads
.gitattributesfromHEAD(the default branch). LFS tracking configured only on other branches will not be detected. - Root
.gitattributesonly: Nested.gitattributesfiles in subdirectories are not inspected. - Detection, not sizing: This column only indicates whether LFS is configured — it does not report the number or size of LFS objects.
- Empty repositories: Empty repositories will always report
FALSEsince there is no.gitattributesfile to read.
For actual LFS sizing, use the standalone script/lfs-size.sh script to inspect individual repositories where Has_LFS is TRUE. This performs a shallow bare clone and reports per-file LFS sizes and totals. See the LFS Sizing Guide for prerequisites and usage.
The project-stats command generates a separate CSV file with the following columns:
Org_Name: Organization loginRepo_Name: Repository nameIssues_Linked_To_Projects: Number of issues that have at least one linked ProjectV2Unique_Projects_Linked_By_Issues: Count of distinct ProjectV2 items found across all issuesProjects_Linked_To_Repo: Total count of projects directly associated with the repository
git clone https://github.com/mona-actions/gh-repo-stats-plus.git
cd gh-repo-stats-plus
npm install
npm run build
npm testSee the Development Guide for detailed setup instructions.
- Node.js 20 or later
- GitHub CLI (latest version recommended)
- GitHub Authentication (personal token, GitHub App, or GitHub CLI)
We welcome contributions! Please see our Development Guide for setup instructions and guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.