Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion gitstats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""gitstats - Beautiful git statistics in your terminal."""

__version__ = "0.1.0"
__version__ = "0.2.0"
25 changes: 21 additions & 4 deletions gitstats/cli.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -63,6 +65,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
Expand Down Expand Up @@ -151,8 +159,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"]),
Expand Down Expand Up @@ -184,7 +193,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"])
Expand All @@ -193,9 +205,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")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading