split total counts for other packages

This commit is contained in:
David Duran Rosich committed 2026-10-25 11:17:45 +01:00
1 parent 66808d77f0
commit 9cabdefdf4
2 files changed
+45 -14

No files matched your search

+33 -8
View File
@@ -1051,7 +1051,7 @@ def _chunk_list(items: list[object], size: int) -> list[list[object]]:
def build_other_containers_bodies(
rows: list[tuple[str, str, int, int, int]],
rows: list,
) -> list[str]:
"""Split the summary by container groups so each message stays small."""
if not rows:
@@ -1059,14 +1059,34 @@ def build_other_containers_bodies(
bodies: list[str] = []
for chunk in _chunk_list(rows, 12):
lines = ["Other containers with findings:", ""]
for image, container, total, fixable, unfixable in chunk:
for row in chunk:
if len(row) == 7:
image, container, total_all, fixable_all, unfixable_all, counts, fixable_counts = row
else:
image, container, total_all, fixable_all, unfixable_all = row
counts = {s: 0 for s in REPORTED_SEVERITIES}
fixable_counts = {s: 0 for s in REPORTED_SEVERITIES}
label = f"{image} [{container}]" if container else image
lines.append(f"* {label}: {fixable}/{total} (fixable/total)")
lines += ["", f"Total: {sum(row[2] for row in chunk)} CVE(s) in {len(chunk)} container(s)"]
lines.append(label)
lines.append(
" ".join(
f"{name[0]} {fixable_counts.get(name, 0)}/{counts.get(name, 0)}"
for name in REPORTED_SEVERITIES
)
)
lines.append(f"Total: {fixable_all}/{total_all}")
lines.append("")
# Remove trailing blank line
if lines and lines[-1] == "":
lines.pop()
total_cves = sum(row[2] for row in chunk)
fixable_cves = sum(row[3] for row in chunk)
lines += ["", f"Total: {fixable_cves}/{total_cves} in {len(chunk)} container(s)"]
bodies.append("\n".join(lines))
if len(bodies) > 1:
overall = f"Total: {sum(row[2] for row in rows)} CVE(s) in {len(rows)} container(s)"
bodies[-1] = bodies[-1] + "\n\n" + overall
overall_fixable = sum(row[3] for row in rows)
overall_total = sum(row[2] for row in rows)
bodies[-1] = bodies[-1] + f"\n\nOverall: {overall_fixable}/{overall_total} in {len(rows)} container(s)"
return bodies
@@ -1407,7 +1427,7 @@ def send_notifications(
)
# One summary notification for every other container.
rows: list[tuple[str, str, int, int, int]] = []
rows: list = []
for target in targets:
result = aggregated.results.get(target.image)
if result is None:
@@ -1416,10 +1436,15 @@ def send_notifications(
if not entries:
continue
total, fixable, unfixable = split_counts(entries)
counts = severity_counts(entries)
fixable_counts = {severity: 0 for severity in REPORTED_SEVERITIES}
for entry in entries:
if entry.fixable:
fixable_counts[entry.severity] += 1
for container in target.containers or [""]:
if container and container in important:
continue
rows.append((target.image, container, total, fixable, unfixable))
rows.append((target.image, container, total, fixable, unfixable, counts, fixable_counts))
if rows:
bodies = build_other_containers_bodies(rows)