fix: align backend commit response with frontend expectations

Backend was returning fields like 'author', 'email', 'date' but frontend
expected 'author_name', 'author_email', 'author_date'. Also 'branches' and
'tags' were separate but frontend expects unified 'refs' array.

- Update _commit_to_dict to return frontend-compatible field names
- Add graph_symbol and graph_depth for commit graph display
- Update get_commit_detail to return matching field names
- Include diff as top-level field for detail view
This commit is contained in:
Fusion
2026-05-19 13:04:49 +02:00
parent d0191cd549
commit d4b52668aa
+37 -13
View File
@@ -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,
}