11from __future__ import annotations
22
3- from collections .abc import Mapping
4- from typing import Any
5-
63_SEVERITIES = ["CRITICAL" , "HIGH" , "MEDIUM" , "LOW" , "INFO" ]
74
85
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
16-
17-
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 ()
6+ def to_markdown (summary : dict ) -> str :
7+ counts = {s : int (summary .get ("by_severity" , {}).get (s , 0 )) for s in _SEVERITIES }
8+ total = int (summary .get ("total" , sum (counts .values ())))
9+ worst = str (summary .get ("worst" , "INFO" )).upper ()
2210 risk = str (summary .get ("risk" , summary .get ("risk_level" , "green" )) or "green" ).lower ()
2311 emoji = {"red" : "🔴" , "yellow" : "🟡" , "green" : "🟢" }.get (risk , "🟢" )
12+
13+ if total == 0 :
14+ return "\n " .join (
15+ [
16+ f"# Diff Risk Dashboard { emoji } — No findings" ,
17+ "" ,
18+ "> ✅ No findings detected (all severities are 0)." ,
19+ "" ,
20+ "> Generated by diff-risk-dashboard CLI" ,
21+ ]
22+ )
23+
2424 lines = [
2525 f"# Diff Risk Dashboard { emoji } — Worst: **{ worst } **" ,
2626 "" ,
@@ -29,5 +29,7 @@ def to_markdown(summary: Mapping[str, Any]) -> str:
2929 ]
3030 for sev in _SEVERITIES :
3131 lines .append (f"| { sev } | { counts .get (sev , 0 )} |" )
32- lines += [f"| **TOTAL** | **{ total } ** |" , "" , "> Generated by diff-risk-dashboard CLI" ]
32+ lines .append (f"| **TOTAL** | **{ total } ** |" )
33+ lines .append ("" )
34+ lines .append ("> Generated by diff-risk-dashboard CLI" )
3335 return "\n " .join (lines )
0 commit comments