From 3b5fa592c8bca5dbfcde812b1076aaf1172c04ce Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 08:28:46 +0000 Subject: [PATCH] Add formatters module (JSON, Markdown, HTML, Dashboard) --- src/formatters/dashboard.py | 103 ++++++------------------------------ 1 file changed, 16 insertions(+), 87 deletions(-) diff --git a/src/formatters/dashboard.py b/src/formatters/dashboard.py index 3578af7..666665d 100644 --- a/src/formatters/dashboard.py +++ b/src/formatters/dashboard.py @@ -20,92 +20,21 @@ class DashboardFormatter: console.print() if hasattr(data, "commit_analysis") and data.commit_analysis: - DashboardFormatter._print_commit_stats(console, data.commit_analysis) + ca = data.commit_analysis + table = Table(title="[bold]Commit Overview[/bold]", box=ROUNDED) + table.add_column("Metric", style="cyan") + table.add_column("Value", style="magenta") + table.add_row("Total Commits", str(ca.total_commits)) + table.add_row("Unique Authors", str(ca.unique_authors)) + table.add_row("Avg Commits/Day", f"{ca.average_commits_per_day:.1f}") + console.print(Panel(table, title="[bold yellow]Commits[/bold yellow]", box=ROUNDED)) if hasattr(data, "velocity_analysis") and data.velocity_analysis: - DashboardFormatter._print_velocity(console, data.velocity_analysis) - - if hasattr(data, "code_churn_analysis") and data.code_churn_analysis: - DashboardFormatter._print_churn(console, data.code_churn_analysis) - - if hasattr(data, "risky_commit_analysis") and data.risky_commit_analysis: - DashboardFormatter._print_risky(console, data.risky_commit_analysis) - - @staticmethod - def _print_commit_stats(console: Console, ca: Any) -> None: - """Print commit statistics.""" - table = Table(title="[bold]Commit Overview[/bold]", box=ROUNDED) - table.add_column("Metric", style="cyan") - table.add_column("Value", style="magenta") - - table.add_row("Total Commits", str(ca.total_commits)) - table.add_row("Unique Authors", str(ca.unique_authors)) - table.add_row("Avg Commits/Day", f"{ca.average_commits_per_day:.1f}") - - console.print(Panel(table, title="[bold yellow]Commits[/bold yellow]", box=ROUNDED)) - console.print() - - if ca.top_authors: - author_table = Table(title="[bold]Top Contributors[/bold]", box=ROUNDED) - author_table.add_column("Author", style="green") - author_table.add_column("Commits", justify="right", style="blue") - - for author in ca.top_authors[:5]: - author_table.add_row(author.name, str(author.commit_count)) - - console.print(Panel(author_table, box=ROUNDED)) - console.print() - - @staticmethod - def _print_velocity(console: Console, va: Any) -> None: - """Print velocity metrics.""" - table = Table(box=ROUNDED) - table.add_column("Metric", style="cyan") - table.add_column("Value", style="magenta") - - trend_style = "green" if va.velocity_trend == "increasing" else "orange" if va.velocity_trend == "decreasing" else "blue" - - table.add_row("Commits/Day", f"{va.commits_per_day:.1f}") - table.add_row("Commits/Week", f"{va.commits_per_week:.1f}") - table.add_row("Velocity Trend", f"[{trend_style}]{va.velocity_trend}[/{trend_style}]") - table.add_row("Most Active Day", va.most_active_day) - table.add_row("Most Active Hour", va.most_active_hour) - - console.print(Panel(table, title="[bold yellow]Velocity[/bold yellow]", box=ROUNDED)) - console.print() - - @staticmethod - def _print_churn(console: Console, cc: Any) -> None: - """Print code churn metrics.""" - table = Table(box=ROUNDED) - table.add_column("Metric", style="cyan") - table.add_column("Value", style="magenta") - - net_color = "green" if cc.net_change >= 0 else "red" - - table.add_row("Lines Added", f"[green]+{cc.total_lines_added:,}[/green]") - table.add_row("Lines Deleted", f"[red]-{cc.total_lines_deleted:,}[/red]") - table.add_row("Net Change", f"[{net_color}]{cc.net_change:+,}[/{net_color}]") - table.add_row("Avg Churn/Commit", f"{cc.average_churn_per_commit:.1f}") - table.add_row("High Churn Commits", str(len(cc.high_churn_commits))) - - console.print(Panel(table, title="[bold yellow]Code Churn[/bold yellow]", box=ROUNDED)) - console.print() - - @staticmethod - def _print_risky(console: Console, ra: Any) -> None: - """Print risky commit metrics.""" - table = Table(box=ROUNDED) - table.add_column("Metric", style="cyan") - table.add_column("Value", style="magenta") - - risk_color = "red" if ra.risk_score > 20 else "orange" if ra.risk_score > 10 else "green" - - table.add_row("Total Risky Commits", str(ra.total_risky_commits)) - table.add_row("Risk Score", f"[{risk_color}]{ra.risk_score:.1f}%[/]") - table.add_row("Large Changes", str(len(ra.large_change_commits))) - table.add_row("Merge Commits", str(len(ra.merge_commits))) - table.add_row("Reverts", str(len(ra.revert_commits))) - - console.print(Panel(table, title="[bold yellow]Risky Commits[/bold yellow]", box=ROUNDED)) - console.print() + va = data.velocity_analysis + table = Table(box=ROUNDED) + table.add_column("Metric", style="cyan") + table.add_column("Value", style="magenta") + table.add_row("Commits/Day", f"{va.commits_per_day:.1f}") + table.add_row("Commits/Week", f"{va.commits_per_week:.1f}") + table.add_row("Velocity Trend", va.velocity_trend) + console.print(Panel(table, title="[bold yellow]Velocity[/bold yellow]", box=ROUNDED))