Skip to content

Commit

Permalink
fix: only show platforms in summary when known
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestelfer committed Mar 15, 2024
1 parent 113fead commit 0e6dfed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/report/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func (c AnnotationContext) Render() ([]byte, error) {
t, err := template.
New("annotation").
Funcs(template.FuncMap{
"hasUntilValue": hasUntilValue,
"hasKnownPlatform": hasKnownPlatform,
"hasUntilValue": hasUntilValue,
"titleCase": func(s string) string {
c := cases.Title(language.English)
return c.String(s)
Expand Down Expand Up @@ -199,3 +200,12 @@ func joinPlatforms(input []v1.Platform) string {
}
return strings.Join(platformValues, ", ")
}

func hasKnownPlatform(input []v1.Platform) bool {
for _, v := range input {
if v.OS != "unknown" {
return true
}
}
return false
}
4 changes: 2 additions & 2 deletions src/report/annotation.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ be wrapped in <p> tag by the Markdown renderer in Buildkite.
{{ $summary := .FindingSummary }}
{{ if .ImageLabel }}
<h4>Vulnerability summary for "{{ .ImageLabel }}"</h4>
<p class="h6 regular italic">{{ .Image.DisplayName }}{{ if $summary.Platforms }} with platform{{ if gt (len $summary.Platforms) 1 }}s{{ end }} {{ joinPlatforms $summary.Platforms }}{{ end }}</p>
<p class="h6 regular italic">{{ .Image.DisplayName }}{{ if (and $summary.Platforms (hasKnownPlatform $summary.Platforms)) }} with platform{{ if gt (len $summary.Platforms) 1 }}s{{ end }} {{ joinPlatforms $summary.Platforms }}{{ end }}</p>
{{ else }}
<h4>Vulnerability summary for "{{ .Image.DisplayName }}"</h4>{{ if $summary.Platforms }}
<h4>Vulnerability summary for "{{ .Image.DisplayName }}"</h4>{{ if (and $summary.Platforms (hasKnownPlatform $summary.Platforms)) }}
<p class="h6 regular italic">Platform{{ if gt (len $summary.Platforms) 1 }}s{{ end }}: {{ joinPlatforms $summary.Platforms }}</p>{{ end }}
{{ end }}
{{ if .FindingSummary.Counts }}
Expand Down

0 comments on commit 0e6dfed

Please sign in to comment.