First MVP
This commit is contained in:
50
src/gitea_codex_bot/services/review_format.py
Normal file
50
src/gitea_codex_bot/services/review_format.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from gitea_codex_bot.types import ParsedCommand
|
||||
|
||||
|
||||
def format_queue_ack(head_sha: str) -> str:
|
||||
short_sha = head_sha[:7]
|
||||
return f"👀 Codex review queued for commit `{short_sha}`."
|
||||
|
||||
|
||||
def format_cooldown_ack(seconds: int) -> str:
|
||||
return f"⏳ Cooldown active. Please wait {seconds}s before requesting another review on this PR."
|
||||
|
||||
|
||||
def format_disabled_ack() -> str:
|
||||
return "🚫 Review is disabled by `.codex-review.yml` for this repository."
|
||||
|
||||
|
||||
def format_unsupported_ack(command: ParsedCommand) -> str:
|
||||
return f"⚠️ Command `@codex {command.name}` is not enabled on this repository."
|
||||
|
||||
|
||||
def format_result_comment(head_sha: str, result: dict) -> str:
|
||||
verdict = result.get("verdict", "has_issues")
|
||||
confidence = float(result.get("confidence", 0.0))
|
||||
summary = str(result.get("summary", "No summary returned."))
|
||||
findings = result.get("findings", []) or []
|
||||
|
||||
lines = [f"<!-- codex-review:head_sha={head_sha} -->", "## Codex Review", "", f"Verdict: `{verdict}`", f"Confidence: `{confidence:.2f}`", "", summary, ""]
|
||||
if not findings:
|
||||
lines.append("No blocking issues found.")
|
||||
else:
|
||||
lines.append("Findings:")
|
||||
for idx, finding in enumerate(findings, start=1):
|
||||
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()
|
||||
Reference in New Issue
Block a user