From fdd3819ff80333aaeb48dbc7fcc9f836b4ba0494 Mon Sep 17 00:00:00 2001 From: Space-Banane Date: Wed, 27 May 2026 22:54:27 +0200 Subject: [PATCH] feat. append structured details to markdown comment in format_result_comment --- src/gitea_codex_bot/services/review_format.py | 41 +++++++++++++++++++ tests/test_review_format.py | 26 +++++++++--- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/gitea_codex_bot/services/review_format.py b/src/gitea_codex_bot/services/review_format.py index b496924..5919ccf 100644 --- a/src/gitea_codex_bot/services/review_format.py +++ b/src/gitea_codex_bot/services/review_format.py @@ -39,6 +39,9 @@ def format_result_comment(head_sha: str, result: dict, *, repo_configured: bool markdown_comment = result.get("markdown_comment") if isinstance(markdown_comment, str) and markdown_comment.strip(): body = markdown_comment.strip() + details = _format_structured_details(result) + if details: + body = f"{body}\n\n---\n\n{details}" if usage_note: body = f"{body}\n\n{usage_note}" if missing_config_note: @@ -108,3 +111,41 @@ def _format_missing_config_note(repo_configured: bool) -> str: if repo_configured: return "" return "> ℹ️.codex-review.yml is not configured" + + +def _format_structured_details(result: dict) -> str: + verdict = str(result.get("verdict", "has_issues")) + summary = str(result.get("summary", "No summary returned.")) + confidence_raw = result.get("confidence", 0.0) + try: + confidence = float(confidence_raw) + except (TypeError, ValueError): + confidence = 0.0 + findings = result.get("findings", []) or [] + + lines = ["### Structured Findings", "", f"Verdict: `{verdict}`", f"Confidence: `{confidence:.2f}`", "", summary, ""] + if not findings: + lines.append("No blocking issues found.") + return "\n".join(lines).strip() + + lines.append("Findings:") + for idx, finding in enumerate(findings, start=1): + if not isinstance(finding, dict): + lines.extend([f"{idx}. `unknown` (unknown)", " Issue", f" {finding}", " Suggestion: n/a"]) + continue + severity = finding.get("severity", "unknown") + file_path = finding.get("file", "unknown") + line_start = finding.get("line_start", "?") + line_end = finding.get("line_end", line_start) + title = finding.get("title", "Issue") + body = finding.get("body", "") + suggestion = finding.get("suggestion", "") + lines.extend( + [ + f"{idx}. `{file_path}:{line_start}-{line_end}` ({severity})", + f" {title}", + f" {body}", + f" Suggestion: {suggestion}" if suggestion else " Suggestion: n/a", + ] + ) + return "\n".join(lines).strip() diff --git a/tests/test_review_format.py b/tests/test_review_format.py index bf98088..b144b18 100644 --- a/tests/test_review_format.py +++ b/tests/test_review_format.py @@ -3,19 +3,33 @@ from __future__ import annotations from gitea_codex_bot.services.review_format import format_result_comment -def test_format_result_comment_uses_markdown_comment_verbatim_with_marker() -> None: +def test_format_result_comment_appends_structured_details_to_markdown_comment() -> None: body = format_result_comment( "abc1234", { - "verdict": "correct", + "verdict": "has_issues", "confidence": 0.9, - "summary": "ignored when markdown_comment exists", - "findings": [], - "markdown_comment": "## Codex Review\n\nAll good.\n\nNo issues found.", + "summary": "2 issues detected.", + "findings": [ + { + "severity": "high", + "file": "src/app.py", + "line_start": 20, + "line_end": 22, + "title": "Unsafe command execution", + "body": "User input is passed directly into shell=True.", + "suggestion": "Use a fixed argument list and avoid shell=True.", + } + ], + "markdown_comment": "## Codex Review\n\nShort agent message only.", }, ) assert body.startswith("\n## Codex Review") - assert "All good.\n\nNo issues found." in body + assert "Short agent message only." in body + assert "### Structured Findings" in body + assert "2 issues detected." in body + assert "`src/app.py:20-22` (high)" in body + assert "Unsafe command execution" in body def test_format_result_comment_replaces_existing_marker() -> None: