diff --git a/apps/api/src/utils/git_history.py b/apps/api/src/utils/git_history.py index b7e459d..7bc9e03 100644 --- a/apps/api/src/utils/git_history.py +++ b/apps/api/src/utils/git_history.py @@ -114,11 +114,26 @@ def get_commit_history(repo_path: str, branch: str | None = None, limit: int = 1 count_output = _run_git_command(repo_path, ["rev-list", "--all", "--count"]) total_commits = int(count_output.strip()) if count_output.strip() else 0 - # Build graph data + # Build graph data and generate graph symbols graph_data = _build_graph_data(commits) + + # Generate simple graph symbols based on parent count + commit_dicts = [] + for i, commit in enumerate(commits): + if len(commit.parents) == 0: + graph_symbol = "○" # Initial commit + elif len(commit.parents) > 1: + graph_symbol = "●" # Merge commit + else: + graph_symbol = "○" # Regular commit + + # Simple depth calculation based on merge status + graph_depth = min(len(commit.parents), 3) + + commit_dicts.append(_commit_to_dict(commit, graph_symbol, graph_depth)) return { - "commits": [_commit_to_dict(c) for c in commits], + "commits": commit_dicts, "branches": branches, "total_commits": total_commits, "graph_data": graph_data, @@ -165,15 +180,18 @@ def get_commit_detail(repo_path: str, commit_hash: str) -> dict[str, Any]: "hash": commit_hash, "short_hash": commit_hash[:7], "parents": parents, - "author": author, - "email": email, - "date": str(timestamp), - "timestamp": timestamp, + "author_name": author, + "author_email": email, + "author_date": str(timestamp), + "committer_name": author, # TODO: extract committer separately + "committer_email": email, # TODO: extract committer separately + "committer_date": str(timestamp), "message": message, "body": body, "branches": branch_map.get(commit_hash, []), "tags": tag_map.get(commit_hash, []), "stats": stats, + "diff": diff_output, "files": [_file_change_to_dict(f) for f in files], } @@ -329,19 +347,25 @@ def _parse_diff(diff_output: str) -> list[FileChange]: return files -def _commit_to_dict(commit: Commit) -> dict[str, Any]: +def _commit_to_dict(commit: Commit, graph_symbol: str = "", graph_depth: int = 0) -> dict[str, Any]: """Convert Commit dataclass to dictionary.""" + refs = [] + if commit.branches: + refs.extend(commit.branches) + if commit.tags: + refs.extend(commit.tags) + return { "hash": commit.hash, "short_hash": commit.short_hash, "parents": commit.parents, - "author": commit.author, - "email": commit.email, - "date": commit.date, - "timestamp": commit.timestamp, + "author_name": commit.author, + "author_email": commit.email, + "author_date": str(commit.timestamp), "message": commit.message, - "branches": commit.branches, - "tags": commit.tags, + "refs": refs, + "graph_symbol": graph_symbol, + "graph_depth": graph_depth, }