feat. append structured details to markdown comment in format_result_comment
This commit is contained in:
@@ -39,6 +39,9 @@ def format_result_comment(head_sha: str, result: dict, *, repo_configured: bool
|
|||||||
markdown_comment = result.get("markdown_comment")
|
markdown_comment = result.get("markdown_comment")
|
||||||
if isinstance(markdown_comment, str) and markdown_comment.strip():
|
if isinstance(markdown_comment, str) and markdown_comment.strip():
|
||||||
body = 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:
|
if usage_note:
|
||||||
body = f"{body}\n\n{usage_note}"
|
body = f"{body}\n\n{usage_note}"
|
||||||
if missing_config_note:
|
if missing_config_note:
|
||||||
@@ -108,3 +111,41 @@ def _format_missing_config_note(repo_configured: bool) -> str:
|
|||||||
if repo_configured:
|
if repo_configured:
|
||||||
return ""
|
return ""
|
||||||
return "> ℹ️.codex-review.yml is not configured"
|
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()
|
||||||
|
|||||||
@@ -3,19 +3,33 @@ from __future__ import annotations
|
|||||||
from gitea_codex_bot.services.review_format import format_result_comment
|
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(
|
body = format_result_comment(
|
||||||
"abc1234",
|
"abc1234",
|
||||||
{
|
{
|
||||||
"verdict": "correct",
|
"verdict": "has_issues",
|
||||||
"confidence": 0.9,
|
"confidence": 0.9,
|
||||||
"summary": "ignored when markdown_comment exists",
|
"summary": "2 issues detected.",
|
||||||
"findings": [],
|
"findings": [
|
||||||
"markdown_comment": "## Codex Review\n\nAll good.\n\nNo issues found.",
|
{
|
||||||
|
"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("<!-- codex-review:head_sha=abc1234 -->\n## Codex Review")
|
assert body.startswith("<!-- codex-review:head_sha=abc1234 -->\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:
|
def test_format_result_comment_replaces_existing_marker() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user