Skip to content

Commit e3a33d4

Browse files
committed
feat(md): clean zero-state in Markdown (No findings + TOTAL only); keep normal table unchanged
1 parent a132c4b commit e3a33d4

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

src/diff_risk_dashboard/report.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
from __future__ import annotations
22

3-
from collections.abc import Mapping
43
from typing import Any
54

65
_SEVERITIES = ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"]
76

87

9-
def _get_counts(summary: Mapping[str, Any]) -> dict[str, int]:
10-
counts: dict[str, int] = {}
11-
by = summary.get("by_severity", {}) or {}
12-
if isinstance(by, Mapping):
13-
for sev in _SEVERITIES:
14-
counts[sev] = int(by.get(sev, by.get(sev.lower(), 0)) or 0)
15-
return counts
8+
def _norm_counts(summary: dict[str, Any]) -> dict[str, int]:
9+
src = summary.get("by_severity") or {}
10+
by = {str(k).upper(): int(v) for k, v in src.items()}
11+
return {s: int(by.get(s, 0)) for s in _SEVERITIES}
1612

1713

18-
def to_markdown(summary: Mapping[str, Any]) -> str:
19-
counts = _get_counts(summary)
20-
total = int(summary.get("total", 0) or 0)
21-
worst = str(summary.get("worst", "INFO") or "INFO").upper()
22-
risk = str(summary.get("risk", summary.get("risk_level", "green")) or "green").lower()
14+
def to_markdown(summary: dict[str, Any]) -> str:
15+
counts = _norm_counts(summary)
16+
total = int(summary.get("total", sum(counts.values())))
17+
worst = str(summary.get("worst") or summary.get("risk_level") or "INFO").upper()
18+
risk = str(summary.get("risk_level", "green") or "green").lower()
2319
emoji = {"red": "🔴", "yellow": "🟡", "green": "🟢"}.get(risk, "🟢")
20+
21+
zero = total == 0 or sum(counts.values()) == 0
22+
if zero:
23+
# Zero-state: limpio y profesional
24+
return "\n".join(
25+
[
26+
f"# Diff Risk Dashboard {emoji} — No findings",
27+
"",
28+
"> ✅ No findings. All severities are 0.",
29+
"",
30+
"| Severity | Count |",
31+
"|---|---:|",
32+
"| **TOTAL** | **0** |",
33+
"",
34+
]
35+
)
36+
37+
# Caso normal: tabla completa (compatibilidad con tests/README)
2438
lines = [
2539
f"# Diff Risk Dashboard {emoji} — Worst: **{worst}**",
2640
"",
@@ -29,5 +43,10 @@ def to_markdown(summary: Mapping[str, Any]) -> str:
2943
]
3044
for sev in _SEVERITIES:
3145
lines.append(f"| {sev} | {counts.get(sev, 0)} |")
32-
lines += [f"| **TOTAL** | **{total}** |", "", "> Generated by diff-risk-dashboard CLI"]
46+
lines.append(f"| **TOTAL** | **{total}** |")
47+
lines.append("")
3348
return "\n".join(lines)
49+
50+
51+
# Alias de compatibilidad
52+
render_markdown = to_markdown

0 commit comments

Comments
 (0)