Spaces:
Runtime error
Runtime error
File size: 2,251 Bytes
77610ec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | import { Request, Response } from "express";
import prisma from "../../prisma/client";
import { getGeminiResponse } from "../../utils/gemini";
import axios from "axios";
export const analyzeCode = async (req: Request, res: Response) => {
const userId = (req as any).user?.id;
const { repoUrl, projectId } = req.body;
try {
// 1. Fetch code from GitHub (simplified: fetch README or a few files for demo)
// In a real app, you'd use a GitHub App or User Token to clone or fetch via API
const repoPath = repoUrl.replace("https://github.com/", "");
const [owner, repo] = repoPath.split("/");
// Fetch repo info as a placeholder for analysis
const githubApiUrl = `https://api.github.com/repos/${owner}/${repo}`;
const repoInfo = await axios.get(githubApiUrl);
// 2. Automated analysis (simulated)
const metrics = {
complexity: "Medium",
securityIssues: 0,
lintErrors: 0
};
// 3. AI-powered feedback
const prompt = `Please review this GitHub repository: ${repoUrl}.
Owner: ${owner}
Repo: ${repo}
Description: ${repoInfo.data.description}
Provide constructive feedback on the project structure and suggest improvements for a student.`;
const feedback = await getGeminiResponse(prompt);
// 4. Store review results
const submission = await prisma.submission.create({
data: {
userId,
projectId,
repoUrl,
feedback,
score: 85 // Simulated score
}
});
res.json({ success: true, data: submission });
} catch (error: any) {
res.status(500).json({ success: false, message: error.message });
}
};
export const getSubmissionReview = async (req: Request, res: Response) => {
const { id } = req.params;
try {
const submission = await prisma.submission.findUnique({
where: { id },
include: {
project: { select: { title: true } },
user: { select: { firstName: true, lastName: true } }
}
});
if (!submission) return res.status(404).json({ success: false, message: "Submission not found" });
res.json({ success: true, data: submission });
} catch (error: any) {
res.status(500).json({ success: false, message: error.message });
}
};
|