feat(reports): store and browse report artifacts

This commit is contained in:
zwitschi committed 2026-11-06 12:27:00 +01:00
1 parent 5967a43eb5
commit 6f2e479958
13 files changed
+875 -93

No files matched your search

+27
View File
@@ -7,6 +7,7 @@
from __future__ import annotations
import hashlib
import os
import re
from collections import Counter
@@ -336,6 +337,7 @@ class Analyzer:
self.write_data()
report_path = self.write_report()
self.persist_report_artifact(report_path, db_scan_id)
print(f"data files: {self.data_dir}")
print(f"summary report: {report_path}")
@@ -349,3 +351,28 @@ class Analyzer:
result.update(rsc=rsc, blocked=n_blocked,
whitelisted=n_whitelisted)
return result
def persist_report_artifact(self, path: str,
scan_id: int | None = None) -> None:
"""Store the rendered summary in SQLite while keeping its file export."""
try:
from .db import get_connection
from .db import repositories as repo
with open(path, "rb") as file:
content = file.read()
stat = os.stat(path)
relative = os.path.relpath(path, self.report_dir).replace(os.sep, "/")
repo.insert_report_artifact(
get_connection(), source=self.name,
report_type="analyzer_summary",
generated_at=datetime.fromtimestamp(
stat.st_mtime).astimezone().isoformat(timespec="seconds"),
payload={"format": "text",
"content": content.decode("utf-8", errors="replace")},
original_path=f"{self.name}/{relative}",
content_sha256=hashlib.sha256(content).hexdigest(),
scan_id=scan_id,
)
except Exception as exc:
if not self.quiet:
print(f"WARN: report artifact DB write skipped ({exc})")