From 5c97af3c4926330976599eda051e2c369562d0b2 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 27 Feb 2026 22:53:05 +0100 Subject: [PATCH 1/2] chore: add --top option and bump version to 0.2.0 Made-with: Cursor --- README.md | 3 +++ gitstats/__init__.py | 2 +- gitstats/cli.py | 23 +++++++++++++++++++---- pyproject.toml | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dc8d15e..6b5e497 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ gitstats stats --since 2025-01-01 --until 2025-12-31 # Filter by author gitstats stats --author "Milan" +# Show only top N contributors +gitstats stats --top 5 + # Combine filters gitstats stats --author "Milan" --since 2025-01-01 --json ``` diff --git a/gitstats/__init__.py b/gitstats/__init__.py index bf5663a..0b9443b 100644 --- a/gitstats/__init__.py +++ b/gitstats/__init__.py @@ -1,3 +1,3 @@ """gitstats - Beautiful git statistics in your terminal.""" -__version__ = "0.1.0" +__version__ = "0.2.0" diff --git a/gitstats/cli.py b/gitstats/cli.py index 3340ac2..7f15cbd 100644 --- a/gitstats/cli.py +++ b/gitstats/cli.py @@ -63,6 +63,12 @@ def stats( "-a", help="Filter commits by author name (case-insensitive, partial match)", ), + top: int = typer.Option( + None, + "--top", + "-t", + help="Show only top N contributors", + ), ) -> None: """Show commit statistics for a git repository.""" import json @@ -151,8 +157,9 @@ def stats( "since": since_date.strftime("%Y-%m-%d") if since_date else None, "until": until_date.strftime("%Y-%m-%d") if until_date else None, "author": author, + "top": top, }, - "authors": stats_data["author_stats"], + "authors": stats_data["author_stats"][:top] if top else stats_data["author_stats"], "streaks": streaks, "weekly_activity": get_weekly_activity(stats_data["commits"]), "hourly_activity": get_hourly_activity(stats_data["commits"]), @@ -184,7 +191,10 @@ def stats( # Show author breakdown table if stats_data.get("author_stats"): - _print_author_table(stats_data["author_stats"]) + author_stats_display = stats_data["author_stats"] + if top and top > 0: + author_stats_display = author_stats_display[:top] + _print_author_table(author_stats_display, top=top, total=len(stats_data["author_stats"])) # Show activity heatmap _print_activity_heatmap(stats_data["commits"]) @@ -193,9 +203,14 @@ def stats( _print_streaks(streaks) -def _print_author_table(author_stats: list[dict]) -> None: +def _print_author_table( + author_stats: list[dict], top: int | None = None, total: int | None = None +) -> None: """Print a table of author statistics.""" - table = Table(title="👥 Commits by Author", show_header=True, header_style="bold cyan") + title = "👥 Commits by Author" + if top and total and top < total: + title += f" (top {top} of {total})" + table = Table(title=title, show_header=True, header_style="bold cyan") table.add_column("Author", style="white", no_wrap=True) table.add_column("Commits", justify="right", style="green") diff --git a/pyproject.toml b/pyproject.toml index bdb4e66..e5155cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "gitstats" -version = "0.1.0" +version = "0.2.0" description = "Beautiful git statistics in your terminal" readme = "README.md" requires-python = ">=3.9" From 5cf4c67ecacbfb83b117cc8917bf62b3b44ca273 Mon Sep 17 00:00:00 2001 From: Milan Date: Fri, 27 Feb 2026 22:57:38 +0100 Subject: [PATCH 2/2] fix: add future annotations for Python 3.9 compatibility Made-with: Cursor --- gitstats/cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gitstats/cli.py b/gitstats/cli.py index 7f15cbd..240bcec 100644 --- a/gitstats/cli.py +++ b/gitstats/cli.py @@ -1,5 +1,7 @@ """Command-line interface for gitstats.""" +from __future__ import annotations + import typer from rich.console import Console from rich.table import Table