114 lines
4.2 KiB
C#
114 lines
4.2 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEngine;
|
|
|
|
namespace RunlevelSystems.DevPlus1.EditorTools
|
|
{
|
|
public static class RLGitReportImporter
|
|
{
|
|
private static readonly string[] ExpectedReports =
|
|
{
|
|
"errors.md",
|
|
"api-reference.md",
|
|
"file-purpose.md",
|
|
"call-map.md",
|
|
"unity-scripts.md",
|
|
"code-docs-summary.md",
|
|
"project-flow.md",
|
|
"summary.md",
|
|
"generated-files.md"
|
|
};
|
|
|
|
public static RLGitReportSummary ImportGitReports()
|
|
{
|
|
RLGitReportSummary summary = new RLGitReportSummary();
|
|
string repoRoot = Directory.GetParent(Application.dataPath).FullName;
|
|
string reportsFolder = Path.Combine(repoRoot, "reports");
|
|
summary.reportsFolderFound = Directory.Exists(reportsFolder);
|
|
|
|
if (!summary.reportsFolderFound)
|
|
{
|
|
summary.notes = "Repository-root reports folder was not found. Run Forgejo reports or local scripts first if Git analysis is needed.";
|
|
foreach (string report in ExpectedReports)
|
|
{
|
|
summary.missingReports.Add("reports/" + report);
|
|
}
|
|
return summary;
|
|
}
|
|
|
|
foreach (string report in ExpectedReports)
|
|
{
|
|
string path = Path.Combine(reportsFolder, report);
|
|
if (File.Exists(path))
|
|
{
|
|
summary.foundReports.Add("reports/" + report);
|
|
}
|
|
else
|
|
{
|
|
summary.missingReports.Add("reports/" + report);
|
|
}
|
|
}
|
|
|
|
string errorsPath = Path.Combine(reportsFolder, "errors.md");
|
|
summary.validationReportFound = File.Exists(errorsPath);
|
|
if (summary.validationReportFound)
|
|
{
|
|
string text = File.ReadAllText(errorsPath);
|
|
summary.validationFoundErrors = text.Contains("CUSTOMER CODE ERRORS FOUND");
|
|
summary.validationWarnings = ExtractCount(text, @"Warnings:\s*(\d+)");
|
|
summary.validationErrors = ExtractCount(text, @"Errors:\s*(\d+)");
|
|
}
|
|
|
|
summary.apiReferenceFound = File.Exists(Path.Combine(reportsFolder, "api-reference.md"));
|
|
summary.filePurposeFound = File.Exists(Path.Combine(reportsFolder, "file-purpose.md"));
|
|
summary.staticCallMapFound = File.Exists(Path.Combine(reportsFolder, "call-map.md"));
|
|
summary.unityScriptReportFound = File.Exists(Path.Combine(reportsFolder, "unity-scripts.md"));
|
|
|
|
ReadProjectFlow(Path.Combine(reportsFolder, "project-flow.md"), summary);
|
|
summary.notes = "Imported repository-root Git reports with best-effort parsing.";
|
|
return summary;
|
|
}
|
|
|
|
private static int ExtractCount(string text, string pattern)
|
|
{
|
|
Match match = Regex.Match(text, pattern);
|
|
if (match.Success && int.TryParse(match.Groups[1].Value, out int value))
|
|
{
|
|
return value;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private static void ReadProjectFlow(string path, RLGitReportSummary summary)
|
|
{
|
|
if (!File.Exists(path))
|
|
{
|
|
return;
|
|
}
|
|
|
|
string[] lines = File.ReadAllLines(path);
|
|
bool inEntry = false;
|
|
bool inImportant = false;
|
|
|
|
foreach (string line in lines)
|
|
{
|
|
if (line.StartsWith("## "))
|
|
{
|
|
inEntry = line.Contains("Likely Entry Point") || line.Contains("Possible Startup");
|
|
inImportant = line.Contains("Important Files");
|
|
continue;
|
|
}
|
|
|
|
if (line.StartsWith("- ") && inEntry)
|
|
{
|
|
summary.likelyEntryPoints.Add(line.Substring(2));
|
|
}
|
|
else if (line.StartsWith("- ") && inImportant)
|
|
{
|
|
summary.importantFiles.Add(line.Substring(2));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|