From c2b53ba0f484599738c30d483d562d12cc160444 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Fri, 30 Jan 2026 20:35:21 +0000 Subject: [PATCH] Initial upload: git-insights-cli with CI/CD workflow --- src/analyzers/commit_pattern.py | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/analyzers/commit_pattern.py diff --git a/src/analyzers/commit_pattern.py b/src/analyzers/commit_pattern.py new file mode 100644 index 0000000..a7ef6ff --- /dev/null +++ b/src/analyzers/commit_pattern.py @@ -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, + )