Files
git-insights-cli/src/formatters/html_formatter.py
7000pctAUTO 86be69ed45
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
Add formatters module (JSON, Markdown, HTML, Dashboard)
2026-02-01 08:28:45 +00:00

58 lines
1.9 KiB
Python

from datetime import datetime
from typing import Any
from jinja2 import Template
from src.formatters.base import BaseFormatter
HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Git Insights Report</title>
<style>
body { font-family: sans-serif; margin: 40px; background: #f5f5f5; }
.container { max-width: 900px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; }
h1 { color: #333; border-bottom: 2px solid #4CAF50; padding-bottom: 10px; }
h2 { color: #555; margin-top: 30px; }
.metric { display: inline-block; background: #e8f5e9; padding: 15px; margin: 10px; border-radius: 5px; }
.metric-value { font-size: 24px; font-weight: bold; color: #2e7d32; }
table { width: 100%; border-collapse: collapse; margin: 20px 0; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
th { background: #4CAF50; color: white; }
</style>
</head>
<body>
<div class="container">
<h1>Git Insights Report</h1>
<p>Generated: {{ timestamp }}</p>
{% if commit_analysis %}
<h2>Commit Analysis</h2>
<div class="metric">
<div class="metric-value">{{ commit_analysis.total_commits }}</div>
<div>Total Commits</div>
</div>
<div class="metric">
<div class="metric-value">{{ commit_analysis.unique_authors }}</div>
<div>Authors</div>
</div>
{% endif %}
</div>
</body>
</html>
"""
class HTMLFormatter(BaseFormatter):
"""HTML output formatter."""
@staticmethod
def format(data: Any) -> str:
"""Format data as HTML."""
template = Template(HTML_TEMPLATE)
return template.render(
timestamp=datetime.now().isoformat(),
commit_analysis=data.commit_analysis if hasattr(data, "commit_analysis") else None,
)