Skip to content

sanesource/monthly-loc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

monthly-loc

npm version License: MIT

A CLI tool to fetch and aggregate monthly lines of code (additions/deletions) contributed by a user across all their GitHub repositories.

Features

  • 📊 Track additions, deletions, and net lines of code
  • 📅 Support for single month or multi-month ranges (last 12 months, etc.)
  • 🏢 Works across personal repos AND organization repos
  • 🚫 Exclude specific repositories
  • 📁 Multiple output formats: table, JSON, CSV
  • ⚡ Optimized API usage with GitHub's commit search

Installation

npm install -g monthly-loc

Or run directly with npx:

npx monthly-loc --months 3

Setup

Create a GitHub Personal Access Token with repo and read:user scopes:

  1. Go to https://github.com/settings/tokens
  2. Click "Generate new token (classic)"
  3. Select scopes: repo and read:user
  4. Copy the token

Set it as an environment variable:

export GITHUB_TOKEN="ghp_your_token_here"

Usage

# Current month stats
monthly-loc

# Last 3 months
monthly-loc --months 3

# Last 12 months (full year)
monthly-loc --months 12

# Specific month
monthly-loc --month 2025-06

# Exclude specific repos
monthly-loc --exclude "test-repo,sandbox"

# Output as JSON
monthly-loc --months 6 --output json

# Output as CSV
monthly-loc --output csv > contributions.csv

# Check another user's public contributions
monthly-loc --user octocat --months 3

# Include forked repositories
monthly-loc --include-forks

# Only count specific file types (e.g., only code files)
monthly-loc --include-files "*.ts,*.js,*.tsx,*.jsx"

# Only count Python files
monthly-loc --include-files "*.py"

# Exclude specific file types from line count
monthly-loc --exclude-files "*.md,package-lock.json"

# Combine both: only JS/TS but exclude tests
monthly-loc --include-files "*.ts,*.js" --exclude-files "*.test.ts,*.spec.js"

# Show individual file stats for each repo
monthly-loc --show-files

# Combine with other flags
monthly-loc --months 3 --show-files --include-files "*.ts,*.js"

Options

Option Description Default
-u, --user GitHub username to fetch contributions for Token owner
-e, --exclude Comma-separated list of repository names to skip None
-f, --exclude-file Path to file with repos to exclude (one per line) None
-m, --month Target month in YYYY-MM format Current month
-n, --months Fetch last N months (e.g., 12 for full year) 1
-o, --output Output format: json, csv, table table
--include-files Only count files matching these patterns All files
--exclude-files Exclude files matching these patterns None
--show-files Show individual file stats for each repo false
--include-forks Include forked repositories false

Sample Output

Table Format (Multi-Month)

GitHub Contributions - 2025-10 to 2025-12
User: akulsr0
================================================================================

📅 MONTHLY BREAKDOWN
--------------------------------------------------------------------------------
Month                  Commits     Additions      Deletions      Net Lines
--------------------------------------------------------------------------------
Oct 2025                     6        +2,085            -53        +2,032
Nov 2025                    33       +63,297         -3,337       +59,960
Dec 2025                     5          +621           -201          +420
--------------------------------------------------------------------------------
TOTAL                       44       +66,003         -3,591       +62,412

📦 BY REPOSITORY
--------------------------------------------------------------------------------
Repository                    Commits    Additions    Deletions    Net Lines
--------------------------------------------------------------------------------
repo-1                             24       +58,241        -3,464       +54,777
bazaar                             17        +7,745          -123        +7,622
repo-2                             2            +8            -1            +7
--------------------------------------------------------------------------------
TOTAL                              44       +66,003        -3,591       +62,412

📊 3 months | 4 repos with activity | 44 commits

JSON Format

monthly-loc --months 3 --output json
{
  "period": "2025-10 to 2025-12",
  "user": "akulsr0",
  "summary": {
    "total_additions": 66003,
    "total_deletions": 3591,
    "net_lines": 62412,
    "repos_with_activity": 4,
    "commits": 44,
    "months_analyzed": 3
  },
  "monthly_breakdown": [...],
  "repositories": [...]
}

Exclude File Format

Create a text file with one repository name per line:

# repos-to-exclude.txt
old-archive
test-sandbox
experimental-stuff

Then use it:

monthly-loc --exclude-file repos-to-exclude.txt

Requirements

  • Node.js 18.0.0 or higher
  • GitHub Personal Access Token

License

MIT © Akul Srivastava

About

A CLI tool to fetch and aggregate monthly lines of code (additions/deletions) contributed by a user across all their GitHub repositories.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors