Count lines of code from GitHub pull requests
Project description
trueloc - Lines of Code Counter
A CLI tool to answer: "How many lines of code have I written since date X?" — counting ALL lines touched via GitHub pull requests and direct commits (not just net diff). For example, a single PR where you add 1000 lines, delete them, then add 1 line = +1001 / -1000. Additions and deletions are summed separately across all commits.
Installation
# Clone and install
git clone https://github.com/basnijholt/trueloc.git
cd trueloc
pip install -e .
# Or with uv
uv pip install -e .
Requires the GitHub CLI (gh) to be installed and authenticated:
gh auth login
Usage
# Count lines from PRs and direct commits since a date
trueloc count USERNAME --since 2023-01-01
# Use relative dates
trueloc count USERNAME --since 5d # 5 days ago
trueloc count USERNAME --since 2w # 2 weeks ago
trueloc count USERNAME --since 3m # 3 months ago
trueloc count USERNAME --since 1y # 1 year ago
trueloc count USERNAME --since "last month"
# Specify a date range
trueloc count USERNAME --since 2024-01-01 --until 2024-06-30
# Count only net diff (not per-commit)
trueloc count USERNAME --since 2023-01-01 --net
# Exclude direct commits (PRs only)
trueloc count USERNAME --since 2023-01-01 --no-direct-commits
# Hide file extension breakdown
trueloc count USERNAME --since 2023-01-01 --no-extensions
# Disable caching (fresh API calls)
trueloc count USERNAME --since 2023-01-01 --no-cache
# Output as JSON for scripting/postprocessing
trueloc count USERNAME --since 2023-01-01 --json
# Clear the cache
trueloc clear-cache
Features
- Per-commit counting (default): Counts every line touched in every commit
- Net diff mode: Alternative mode that only counts final diff (
--net) - Direct commits: Includes commits pushed directly to main (not via PR)
- File extension breakdown: Shows which languages you've worked with
- JSON output: Machine-readable output for scripting (
--json) - Disk caching: Uses diskcache to avoid hammering the GitHub API
- Rate limit handling: Automatically waits when rate limited with progress bar
- Flexible dates: Supports relative (
5d,2w,3m,1y) and natural language (last month)
Caching Strategy
- Immutable data (cached forever): commit stats, PR commits, PR files
- Mutable data (1 day TTL): user repos, merged PR lists
Cache is stored in ~/.cache/trueloc/.
Tech Stack
- Python 3.12+
- Typer - CLI framework
- httpx - HTTP client
- Rich - Terminal output
- diskcache - Persistent caching
- dateparser - Flexible date parsing
- Hatch - Build system
- Ruff + mypy - Linting/typing
Development
# Install dev dependencies
uv sync --group dev
# Run tests
pytest
# Run linting
ruff check .
ruff format .
mypy .
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trueloc-0.1.0.tar.gz.
File metadata
- Download URL: trueloc-0.1.0.tar.gz
- Upload date:
- Size: 63.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
682d3c863591bbd8876b02f9788c117ba23b99f597a73a599c4d396cb0938a2b
|
|
| MD5 |
d670d3ed53510f3aa525ac9540a5f9cb
|
|
| BLAKE2b-256 |
45e1e771e46d60148d1d58e4af3db8201f6e2f306357556b4938977352c308b5
|
Provenance
The following attestation bundles were made for trueloc-0.1.0.tar.gz:
Publisher:
release.yml on basnijholt/trueloc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trueloc-0.1.0.tar.gz -
Subject digest:
682d3c863591bbd8876b02f9788c117ba23b99f597a73a599c4d396cb0938a2b - Sigstore transparency entry: 832363233
- Sigstore integration time:
-
Permalink:
basnijholt/trueloc@7770c09527d37bd3f0a1527d8ed35fdbccb04a18 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/basnijholt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7770c09527d37bd3f0a1527d8ed35fdbccb04a18 -
Trigger Event:
release
-
Statement type:
File details
Details for the file trueloc-0.1.0-py3-none-any.whl.
File metadata
- Download URL: trueloc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf820a8f35764e8d53a1f544785b0acd91c3abad3b1385f2cc20691ca08e2858
|
|
| MD5 |
88173f9e5bfa6c9aa1ea7d08745833c0
|
|
| BLAKE2b-256 |
761004b83644510fd25ebb3fb3fa0c760ac8ce80098a93e0bf553efc8c7289ac
|
Provenance
The following attestation bundles were made for trueloc-0.1.0-py3-none-any.whl:
Publisher:
release.yml on basnijholt/trueloc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trueloc-0.1.0-py3-none-any.whl -
Subject digest:
bf820a8f35764e8d53a1f544785b0acd91c3abad3b1385f2cc20691ca08e2858 - Sigstore transparency entry: 832363254
- Sigstore integration time:
-
Permalink:
basnijholt/trueloc@7770c09527d37bd3f0a1527d8ed35fdbccb04a18 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/basnijholt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7770c09527d37bd3f0a1527d8ed35fdbccb04a18 -
Trigger Event:
release
-
Statement type: