From 6a7bf4e993a476cd9688f78bc373702747cd9cac Mon Sep 17 00:00:00 2001 From: sg Date: Tue, 15 Oct 2024 10:17:35 +0100 Subject: [PATCH] fix #422, allow consumer templating to also carry information about which annotation contains the code fix --- pkg/templating/template_description.go | 23 ++++++++++++++------- pkg/templating/template_description_test.go | 8 +++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pkg/templating/template_description.go b/pkg/templating/template_description.go index d40b9556d..139ec80ec 100644 --- a/pkg/templating/template_description.go +++ b/pkg/templating/template_description.go @@ -20,13 +20,14 @@ const ( type ( enrichedIssue struct { *v1.EnrichedIssue - ToolName string - ScanStartTime string - ScanID string - ConfidenceText string - SeverityText string - Count uint - FirstFound string + ToolName string + ScanStartTime string + ScanID string + ConfidenceText string + SeverityText string + Count uint + FirstFound string + FixedCodeAnnotation string } enrichedIssueOption func(*enrichedIssue) error @@ -126,6 +127,14 @@ func EnrichedIssueWithFirstFound(firstFound time.Time) enrichedIssueOption { } } +// EnrichedIssueWithFixedCodeAnnotation allows to define which of the annotations contains fixed code +func EnrichedIssueWithFixedCodeAnnotation(fixedCodeAnnotation string) enrichedIssueOption { + return func(ei *enrichedIssue) error { + ei.FixedCodeAnnotation = fixedCodeAnnotation + return nil + } +} + // TemplateStringEnriched applies the provided go template to the Enriched Issue provided and returns the resulting str func TemplateStringEnriched(inputTemplate string, issue *v1.EnrichedIssue, opts ...enrichedIssueOption) (*string, error) { enrichedIssue := &enrichedIssue{ diff --git a/pkg/templating/template_description_test.go b/pkg/templating/template_description_test.go index 31de76cf6..859a3930d 100644 --- a/pkg/templating/template_description_test.go +++ b/pkg/templating/template_description_test.go @@ -242,6 +242,14 @@ func TestDescriptionOptions(t *testing.T) { ScanID: "scan-1", }, }, + { + name: "valid code scan annotation returns no err", + option: EnrichedIssueWithFixedCodeAnnotation("fixedCode"), + wantErr: false, + expectedEnrichedIssue: &enrichedIssue{ + FixedCodeAnnotation: "fixedCode", + }, + }, } { t.Run(tt.name, func(t *testing.T) { var ei enrichedIssue