Initial upload: git-insights-cli with CI/CD workflow
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled

This commit is contained in:
2026-01-30 20:35:21 +00:00
parent be4dd0f0a7
commit c2b53ba0f4

View File

@@ -0,0 +1,64 @@
from collections import defaultdict
from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, List, Optional
from src.analyzers.git_repository import GitRepository
from src.models.data_structures import Author, CommitAnalysis
@dataclass
class CommitPatternAnalyzer:
"""Analyzes commit patterns."""
repo: GitRepository
days: int
def analyze(self) -> Optional[CommitAnalysis]:
"""Analyze commit patterns."""
commits = self.repo.get_commits()
if not commits:
return None
commits_by_hour: Dict[str, int] = defaultdict(int)
commits_by_day: Dict[str, int] = defaultdict(int)
commits_by_week: Dict[str, int] = defaultdict(int)
author_commits: Dict[str, List[str]] = defaultdict(list)
for commit in commits:
hour_key = commit.timestamp.strftime("%H:00")
day_key = commit.timestamp.strftime("%A")
week_key = commit.timestamp.strftime("%Y-W%U")
commits_by_hour[hour_key] += 1
commits_by_day[day_key] += 1
commits_by_week[week_key] += 1
author_commits[commit.author_email].append(commit.sha)
authors = []
for email, commit_shas in author_commits.items():
author = self.repo.get_authors()
for a in author:
if a.email == email:
a.commit_count = len(commit_shas)
authors.append(a)
break
authors.sort(key=lambda a: a.commit_count, reverse=True)
top_authors = authors[:10]
total_days = max(1, self.days)
avg_commits_per_day = len(commits) / total_days
return CommitAnalysis(
total_commits=len(commits),
unique_authors=len(authors),
commits_by_hour=dict(commits_by_hour),
commits_by_day=dict(commits_by_day),
commits_by_week=dict(commits_by_week),
top_authors=top_authors,
average_commits_per_day=avg_commits_per_day,
)