From 6067b78bcf86433704f437ddf81bdba455bbfdaa Mon Sep 17 00:00:00 2001 From: Ice3man Date: Fri, 10 May 2024 21:59:03 +0530 Subject: [PATCH] feat: added MarshalYAML to severities array + issue tracker options fix (#5166) * feat: added MarshalYAML to severities array * fix issue with creation of reports --- pkg/model/types/severity/severities.go | 8 ++++++++ pkg/model/types/severity/severity_test.go | 9 +++++++++ pkg/reporting/reporting.go | 1 + pkg/reporting/trackers/gitea/gitea.go | 2 +- pkg/reporting/trackers/github/github.go | 2 +- pkg/reporting/trackers/gitlab/gitlab.go | 2 +- pkg/reporting/trackers/jira/jira.go | 2 +- 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/model/types/severity/severities.go b/pkg/model/types/severity/severities.go index a4eb136e2..193a9e45e 100644 --- a/pkg/model/types/severity/severities.go +++ b/pkg/model/types/severity/severities.go @@ -26,6 +26,14 @@ func (severities *Severities) Set(values string) error { return nil } +func (severities Severities) MarshalYAML() (interface{}, error) { + var stringSeverities = make([]string, 0, len(severities)) + for _, severity := range severities { + stringSeverities = append(stringSeverities, severity.String()) + } + return stringSeverities, nil +} + func (severities *Severities) UnmarshalYAML(unmarshal func(interface{}) error) error { var stringSliceValue stringslice.StringSlice if err := unmarshal(&stringSliceValue); err != nil { diff --git a/pkg/model/types/severity/severity_test.go b/pkg/model/types/severity/severity_test.go index e52ed42f4..10d2050de 100644 --- a/pkg/model/types/severity/severity_test.go +++ b/pkg/model/types/severity/severity_test.go @@ -74,3 +74,12 @@ func TestMarshalJSON(t *testing.T) { } require.Equal(t, "[\"low\",\"medium\"]", string(data), "could not marshal json") } + +func TestSeveritiesMarshalYaml(t *testing.T) { + unmarshalled := Severities{Low, Medium} + marshalled, err := yaml.Marshal(unmarshalled) + if err != nil { + panic(err) + } + require.Equal(t, "- low\n- medium\n", string(marshalled), "could not marshal yaml") +} diff --git a/pkg/reporting/reporting.go b/pkg/reporting/reporting.go index c9fe0f4ba..08f32e931 100644 --- a/pkg/reporting/reporting.go +++ b/pkg/reporting/reporting.go @@ -276,6 +276,7 @@ func (c *ReportingClient) CreateIssue(event *output.ResultEvent) error { if tracker.ShouldFilter(event) { continue } + trackerName := tracker.Name() stats, statsOk := c.stats[trackerName] diff --git a/pkg/reporting/trackers/gitea/gitea.go b/pkg/reporting/trackers/gitea/gitea.go index 70fbe7fe5..acb82a1de 100644 --- a/pkg/reporting/trackers/gitea/gitea.go +++ b/pkg/reporting/trackers/gitea/gitea.go @@ -140,7 +140,7 @@ func (i *Integration) CloseIssue(event *output.ResultEvent) error { // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { - return true + return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) { diff --git a/pkg/reporting/trackers/github/github.go b/pkg/reporting/trackers/github/github.go index 102692e6c..44c06102c 100644 --- a/pkg/reporting/trackers/github/github.go +++ b/pkg/reporting/trackers/github/github.go @@ -176,7 +176,7 @@ func (i *Integration) Name() string { // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { - return true + return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) { diff --git a/pkg/reporting/trackers/gitlab/gitlab.go b/pkg/reporting/trackers/gitlab/gitlab.go index dc5bef0d6..769165ad4 100644 --- a/pkg/reporting/trackers/gitlab/gitlab.go +++ b/pkg/reporting/trackers/gitlab/gitlab.go @@ -165,7 +165,7 @@ func (i *Integration) CloseIssue(event *output.ResultEvent) error { // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { - return true + return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) { diff --git a/pkg/reporting/trackers/jira/jira.go b/pkg/reporting/trackers/jira/jira.go index 97ae07831..0b8f27fc5 100644 --- a/pkg/reporting/trackers/jira/jira.go +++ b/pkg/reporting/trackers/jira/jira.go @@ -315,7 +315,7 @@ func (i *Integration) FindExistingIssue(event *output.ResultEvent) (jira.Issue, // ShouldFilter determines if an issue should be logged to this tracker func (i *Integration) ShouldFilter(event *output.ResultEvent) bool { if i.options.AllowList != nil && i.options.AllowList.GetMatch(event) { - return true + return false } if i.options.DenyList != nil && i.options.DenyList.GetMatch(event) {