Link HTML5 review findings to source
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 01:52:28 +03:00
parent 2aaf5d0082
commit de119c2106
3 changed files with 46 additions and 2 deletions
+16 -2
View File
@@ -433,7 +433,7 @@ def render_html5_review(
if not findings:
body = '<p class="muted padded">Findings не найдены</p>'
else:
body = "".join(_review_item(finding) for finding in findings[:12])
body = "".join(_review_item(project_id, finding) for finding in findings[:12])
return f"""
<div
class="review-panel"
@@ -1463,18 +1463,32 @@ def _preflight_item(item: object) -> str:
"""
def _review_item(finding: dict) -> str:
def _review_item(project_id: str, finding: dict) -> str:
title = str(finding.get("title") or finding.get("code") or "Finding")
severity = str(finding.get("severity") or finding.get("level") or "INFO")
message = str(finding.get("message") or finding.get("description") or "")
source_path = str(finding.get("source_path") or finding.get("path") or "")
line = finding.get("line_start") or finding.get("line")
location = f"{source_path}:{line}" if source_path and line else source_path
source_link = (
f"""
<a
href="/html5/projects/{quote(project_id)}/source/by-path?path={quote(source_path, safe='')}"
hx-get="/html5/projects/{quote(project_id)}/source/by-path?path={quote(source_path, safe='')}"
hx-target="[data-html5-source]"
hx-swap="outerHTML"
data-html5-review-source="{escape(source_path)}"
>Source</a>
"""
if source_path
else ""
)
return f"""
<article class="review-item" data-html5-review-finding="{escape(severity)}">
<strong>{escape(title)}</strong>
<span>{escape(severity)}</span>
<small>{escape(message or location or "no details")}</small>
<span class="inline-actions">{source_link}</span>
</article>
"""
@@ -1713,6 +1713,25 @@ async def html5_project_symbol_detail(project_id: str, lineage_id: str) -> Respo
)
@app.get("/html5/projects/{project_id}/source/by-path")
async def html5_project_source_by_path(project_id: str, path: str) -> Response:
snapshot = _project_snapshot_or_404(project_id)
node = next(
(
item
for item in snapshot.nodes
if item.source_ref is not None and item.source_ref.source_path == path
),
None,
)
if node is None:
raise HTTPException(status_code=404, detail=f"Source not found: {path}")
return Response(
render_html5_source(node),
media_type="text/html; charset=utf-8",
)
@app.get("/html5/projects/{project_id}/source/{lineage_id}")
async def html5_project_source(project_id: str, lineage_id: str) -> Response:
snapshot = _project_snapshot_or_404(project_id)