alitheg commented on code in PR #442:
URL: 
https://github.com/apache/tooling-trusted-releases/pull/442#discussion_r2645475557


##########
atr/get/sbom.py:
##########
@@ -378,45 +388,96 @@ def _missing_tally(items: 
list[sbom.models.conformance.Missing]) -> list[tuple[s
     )
 
 
+# TODO: Update this to return either a block or something we can use later in 
a block for styling reasons
 def _license_tally(
     items: list[sbom.models.licenses.Issue],
-) -> list[tuple[sbom.models.licenses.Category, int, list[str | None]]]:
+    old_issues: list[sbom.models.licenses.Issue],
+) -> list[tuple[sbom.models.licenses.Category, int, int, list[str | None]]]:
     counts: dict[sbom.models.licenses.Category, int] = {}
     components: dict[sbom.models.licenses.Category, list[str | None]] = {}
+    new_count = 0
+    old_map = {lic.component_name: (lic.license_expression, lic.category) for 
lic in old_issues}
     for item in items:
         key = item.category
         counts[key] = counts.get(key, 0) + 1
+        name = str(item).capitalize()
+        if item.component_name not in old_map:
+            new_count = new_count + 1
+            name = f"{name} (new)"
+        elif item.license_expression != old_map[item.component_name][0]:
+            new_count = new_count + 1
+            name = f"{name} (previously {old_map[item.component_name][0]} - 
Category {
+                str(old_map[item.component_name][1]).upper()
+            })"
         if key not in components:
-            components[key] = [str(item)]
+            components[key] = [name]
         else:
-            components[key].append(str(item))
+            components[key].append(name)
     return sorted(
-        [(category, count, components.get(category, [])) for category, count 
in counts.items()],
+        [(category, count, new_count, components.get(category, [])) for 
category, count in counts.items()],
         key=lambda kv: kv[0].value,
     )
 
 
-def _vulnerability_component_details_osv(block: htm.Block, component: 
results.OSVComponent) -> None:
-    details_content = []
-    summary_element = htm.summary[
-        
htm.span(".badge.bg-danger.me-2.font-monospace")[str(len(component.vulnerabilities))],
-        htm.strong[component.purl],
-    ]
-    details_content.append(summary_element)
-
+def _severity_to_style(severity: str) -> str:
+    match severity.lower():
+        case "critical":
+            return ".bg-danger.text-light"
+        case "high":
+            return ".bg-danger.text-light"
+        case "medium":
+            return ".bg-warning.text-dark"
+        case "moderate":
+            return ".bg-warning.text-dark"
+        case "low":
+            return ".bg-warning.text-dark"
+        case "info":
+            return ".bg-info.text-light"
+    return ".bg-info.text-light"
+
+
+def _vulnerability_component_details_osv(
+    block: htm.Block,
+    component: results.OSVComponent,
+    previous_vulns: dict[str, str] | None,  # id: severity
+) -> int:
+    severities = ["critical", "high", "medium", "moderate", "low", "info", 
"none", "unknown"]
+    new = 0
+    worst = 99
+
+    vuln_details = []
     for vuln in component.vulnerabilities:
+        is_new = False
         vuln_id = vuln.id or "Unknown"
         vuln_summary = vuln.summary
         vuln_refs = []
         if vuln.references is not None:
             vuln_refs = [r for r in vuln.references if r.get("type", "") == 
"WEB"]
         vuln_primary_ref = vuln_refs[0] if (len(vuln_refs) > 0) else {}
         vuln_modified = vuln.modified or "Unknown"
+
         vuln_severity = _extract_vulnerability_severity(vuln)
+        worst = _update_worst_severity(severities, vuln_severity, worst)
+
+        if previous_vulns is not None:
+            if (vuln_id not in previous_vulns) or previous_vulns[vuln_id] != 
vuln_severity:

Review Comment:
   I think what I've done does this now - I updated the list of previous 
vulnerabilities to include the affected bom-ref from the CDX version. The OSV 
schema doesn't include the component because it's just the vulnerability itself.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to