Spaces:
Paused
Paused
Update app/main.py
Browse files- app/main.py +41 -1
app/main.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
# main.py - Final Fixed Version
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from pydantic import BaseModel
|
| 4 |
-
from typing import List, Optional
|
|
|
|
| 5 |
import logging
|
| 6 |
|
| 7 |
from app.services.reviewer_service import AIReviewerService
|
|
@@ -74,6 +75,45 @@ async def review_code(request: ReviewRequest):
|
|
| 74 |
logger.error(f"Review endpoint failed: {e}")
|
| 75 |
raise HTTPException(status_code=500, detail=str(e))
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# 5. Application Entry Point
|
| 78 |
if __name__ == "__main__":
|
| 79 |
import uvicorn
|
|
|
|
| 1 |
# main.py - Final Fixed Version
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from pydantic import BaseModel
|
| 4 |
+
from typing import List, Optional
|
| 5 |
+
import re
|
| 6 |
import logging
|
| 7 |
|
| 8 |
from app.services.reviewer_service import AIReviewerService
|
|
|
|
| 75 |
logger.error(f"Review endpoint failed: {e}")
|
| 76 |
raise HTTPException(status_code=500, detail=str(e))
|
| 77 |
|
| 78 |
+
@app.post("/repo-dashboard-stats")
|
| 79 |
+
async def get_dashboard_stats(request: ReviewRequest):
|
| 80 |
+
"""
|
| 81 |
+
Specific endpoint for the Jetpack Compose Dashboard.
|
| 82 |
+
Combines CodeBERT classification and Gemini review stats.
|
| 83 |
+
"""
|
| 84 |
+
try:
|
| 85 |
+
# 1. Run the existing Review Logic
|
| 86 |
+
raw_reviews = reviewer_service.review_batch_code(request.files)
|
| 87 |
+
|
| 88 |
+
# 2. Extract Security Count
|
| 89 |
+
total_vulns = sum(len(r.get("vulnerabilities", [])) for r in raw_reviews)
|
| 90 |
+
|
| 91 |
+
# 3. Calculate Performance (Maintainability)
|
| 92 |
+
scores = [r.get("metrics", {}).get("maintainability", 8) for r in raw_reviews]
|
| 93 |
+
avg_maintainability = (sum(scores) / len(scores)) * 10 if scores else 0
|
| 94 |
+
|
| 95 |
+
# 4. Extract Exposed APIs (Sniffing from content)
|
| 96 |
+
found_apis = []
|
| 97 |
+
for f in request.files:
|
| 98 |
+
if f.content:
|
| 99 |
+
# Simple regex to find common route patterns
|
| 100 |
+
matches = re.findall(r'(?:get|post|put|delete|patch)\([\'"]\/(.*?)[\'"]', f.content.lower())
|
| 101 |
+
for match in matches:
|
| 102 |
+
found_apis.append(f"/{match}")
|
| 103 |
+
|
| 104 |
+
# 5. Repo Health Logic
|
| 105 |
+
health_score = max(10, 100 - (total_vulns * 10))
|
| 106 |
+
|
| 107 |
+
return {
|
| 108 |
+
"repo_health": f"{health_score}%",
|
| 109 |
+
"security_issues": total_vulns,
|
| 110 |
+
"performance_ratio": f"{int(avg_maintainability)}%",
|
| 111 |
+
"exposed_apis": list(set(found_apis))[:10] # Top 10 unique routes
|
| 112 |
+
}
|
| 113 |
+
except Exception as e:
|
| 114 |
+
logger.error(f"Dashboard stats failed: {e}")
|
| 115 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 116 |
+
|
| 117 |
# 5. Application Entry Point
|
| 118 |
if __name__ == "__main__":
|
| 119 |
import uvicorn
|