update
All checks were successful
Enterprise AI Code Review / ai-review (pull_request) Successful in 32s

This commit is contained in:
2025-12-28 14:10:04 +00:00
parent c17a61b27a
commit 69d9963597
17 changed files with 627 additions and 444 deletions

View File

@@ -96,7 +96,9 @@ class CodebaseAgent(BaseAgent):
def execute(self, context: AgentContext) -> AgentResult:
"""Execute codebase analysis."""
self.logger.info(f"Starting codebase analysis for {context.owner}/{context.repo}")
self.logger.info(
f"Starting codebase analysis for {context.owner}/{context.repo}"
)
actions_taken = []
@@ -192,7 +194,7 @@ class CodebaseAgent(BaseAgent):
# Check for docstrings (Python)
if ext == ".py":
if 'def ' in content and '"""' not in content:
if "def " in content and '"""' not in content:
metrics.missing_docstrings += 1
except Exception as e:
@@ -273,23 +275,45 @@ Be constructive and actionable. Focus on the most impactful improvements.
)
except Exception as e:
self.logger.error(f"AI analysis failed: {e}")
# Try to log the raw response if possible (requires accessing the last response)
# Since we don't have direct access here, we rely on having good logging in LLMClient if needed.
# But let's add a note to the summary.
self.logger.debug(f"Full error details: {type(e).__name__}: {str(e)}")
# Calculate basic health score from metrics
health_score = 70
if metrics.todo_count > 10:
health_score -= 10
if metrics.fixme_count > 5:
health_score -= 10
if metrics.deprecated_count > 3:
health_score -= 5
# Build recommendations based on metrics
recommendations = []
if metrics.todo_count > 5:
recommendations.append(
f"Review and address {metrics.todo_count} TODO comments"
)
if metrics.fixme_count > 0:
recommendations.append(
f"Review and fix {metrics.fixme_count} FIXME markers"
)
if metrics.deprecated_count > 0:
recommendations.append(
f"Update {metrics.deprecated_count} deprecated code sections"
)
if metrics.missing_docstrings > 5:
recommendations.append("Consider adding more documentation")
if not recommendations:
recommendations.append("Codebase appears well-maintained")
return CodebaseReport(
summary=f"Basic analysis complete (AI unavailable: {e})",
summary=f"Basic metrics analysis complete. {metrics.total_files} files analyzed across {len(metrics.languages)} languages.",
health_score=health_score,
metrics=metrics,
issues=[],
recommendations=["Manual review recommended"],
architecture_notes=[],
recommendations=recommendations,
architecture_notes=[
f"Primary languages: {', '.join(list(metrics.languages.keys())[:3])}"
],
)
def _get_key_files_content(
@@ -386,7 +410,11 @@ Be constructive and actionable. Focus on the most impactful improvements.
def _generate_report_body(self, report: CodebaseReport) -> str:
"""Generate the report issue body."""
health_emoji = "🟢" if report.health_score >= 80 else ("🟡" if report.health_score >= 60 else "🔴")
health_emoji = (
"🟢"
if report.health_score >= 80
else ("🟡" if report.health_score >= 60 else "🔴")
)
lines = [
f"{self.AI_DISCLAIMER}",
@@ -427,7 +455,11 @@ Be constructive and actionable. Focus on the most impactful improvements.
lines.append("")
for issue in report.issues[:10]:
severity = issue.get("severity", "MEDIUM")
emoji = "🔴" if severity == "HIGH" else ("🟡" if severity == "MEDIUM" else "🟢")
emoji = (
"🔴"
if severity == "HIGH"
else ("🟡" if severity == "MEDIUM" else "🟢")
)
lines.append(f"### [{severity}] {issue.get('category', 'General')}")
lines.append("")
lines.append(issue.get("description", ""))