Initial implementation: AI code review bot for Gitea
- CLI binary with flag/env var configuration - Gitea API client (PR metadata, diff, CI status, post review) - OpenAI-compatible LLM client - Structured review prompt with conventions support - JSON response parser with validation - Markdown review formatter for Gitea - CI failure auto-detection (REQUEST_CHANGES) - Dry-run mode for testing
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package review
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FormatMarkdown formats a ReviewResult into the markdown body for a Gitea review.
|
||||
func FormatMarkdown(result *ReviewResult, reviewerName string) string {
|
||||
var sb strings.Builder
|
||||
|
||||
sb.WriteString("## Summary\n\n")
|
||||
sb.WriteString(result.Summary)
|
||||
sb.WriteString("\n\n")
|
||||
|
||||
if len(result.Findings) > 0 {
|
||||
sb.WriteString("## Findings\n\n")
|
||||
sb.WriteString("| # | Severity | File | Line | Finding |\n")
|
||||
sb.WriteString("|---|----------|------|------|--------|\n")
|
||||
|
||||
for i, f := range result.Findings {
|
||||
sb.WriteString(fmt.Sprintf("| %d | [%s] | `%s` | %d | %s |\n",
|
||||
i+1, f.Severity, f.File, f.Line, f.Finding))
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
sb.WriteString("## Recommendation\n\n")
|
||||
sb.WriteString(fmt.Sprintf("**%s** — %s\n", result.Verdict, result.Recommendation))
|
||||
|
||||
if reviewerName != "" {
|
||||
sb.WriteString(fmt.Sprintf("\n---\n*Review by %s*\n", reviewerName))
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// GiteaEvent converts the verdict to the Gitea API event string.
|
||||
func GiteaEvent(verdict string) string {
|
||||
switch verdict {
|
||||
case "APPROVE":
|
||||
return "APPROVED"
|
||||
case "REQUEST_CHANGES":
|
||||
return "REQUEST_CHANGES"
|
||||
default:
|
||||
return "COMMENT"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user