Duo-Guardian / dashboard /src /lib /utils.ts
Daksh C Jain
fix: complete raw ASGI router implementation for SSE
da2bf0a
import { fetchGitLab } from "./gitlab";
export const parseAuditReport = (text: string) => {
if (!text) return null;
const reportRegex = /### 🧠 Context Brain: Intelligence Report([\s\S]*?)(?=---|$|<!--)/i;
const match = text.match(reportRegex);
if (match) return match[1].trim();
if (text.includes("## 🧩 Context Brain: Full Platform Audit")) {
return text.split("## 🧩 Context Brain: Full Platform Audit")[1].split("---")[0].trim();
}
return null;
};
export const splitReportIntoSections = (report: string) => {
if (!report) return {};
const sections: Record<string, string> = {
summary: "",
finops: "",
devops: "",
testing: "",
code: ""
};
const finopsBullet = report.match(/- \*\*FinOps\*\*:([\s\S]*?)(?=- \*\*|$)/i);
const devopsBullet = report.match(/- \*\*DevOps\*\*:([\s\S]*?)(?=- \*\*|$)/i);
const testingBullet = report.match(/- \*\*Tests\*\*:([\s\S]*?)(?=- \*\*|$)/i);
if (finopsBullet) sections.finops = finopsBullet[1].trim();
if (devopsBullet) sections.devops = devopsBullet[1].trim();
if (testingBullet) sections.testing = testingBullet[1].trim();
const finopsHeader = report.match(/#### (?:πŸ’Έ|πŸ’°) Cloud FinOps & Cost Logic([\s\S]*?)(?=####|---|$)/i);
const devopsHeader = report.match(/#### (?:βš™οΈ|πŸš€) DevOps & SRE Review([\s\S]*?)(?=####|---|$)/i);
const testingHeader = report.match(/#### (?:πŸ§ͺ|βœ…) Quality SDET Validation([\s\S]*?)(?=####|---|$)/i);
const codeHeader = report.match(/#### (?:πŸ•΅οΈ|πŸ”’) Code Analyst Audit([\s\S]*?)(?=####|---|$)/i);
if (finopsHeader) sections.finops = finopsHeader[1].trim();
if (devopsHeader) sections.devops = devopsHeader[1].trim();
if (testingHeader) sections.testing = testingHeader[1].trim();
if (codeHeader) sections.code = codeHeader[1].trim();
const summaryPart = report.split(/####|- \*\*/)[0];
sections.summary = summaryPart.replace(/\*\*Analysis\*\*:/i, '').trim();
return sections;
};
export const getRiskStatus = (labels: string[]) => {
if (labels.some(l => l.includes("risk-high") || l.includes("security-critical"))) return "CRITICAL";
if (labels.some(l => l.includes("risk-medium") || l.includes("warning"))) return "CAUTION";
return "STABLE";
};
export const getFileImpact = (filename: string, report: string) => {
const lowercase = filename.toLowerCase();
if (lowercase.includes("secret") || lowercase.includes(".env") || report.toLowerCase().includes(lowercase + " introduces security")) return "HIGH";
if (lowercase.includes("config") || lowercase.includes("yaml") || lowercase.includes("json")) return "MEDIUM";
return "LOW";
};