Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #422, allow consumer templating to also carry information about w… #423

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions pkg/templating/template_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
andream16 marked this conversation as resolved.
Show resolved Hide resolved
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{
Expand Down
8 changes: 8 additions & 0 deletions pkg/templating/template_description_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down