Skip to content

Commit

Permalink
feat: added MarshalYAML to severities array + issue tracker options f…
Browse files Browse the repository at this point in the history
…ix (#5166)

* feat: added MarshalYAML to severities array

* fix issue with creation of reports
  • Loading branch information
Ice3man543 committed May 10, 2024
1 parent fed10a1 commit 6067b78
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions pkg/model/types/severity/severities.go
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/model/types/severity/severity_test.go
Expand Up @@ -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")
}
1 change: 1 addition & 0 deletions pkg/reporting/reporting.go
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion pkg/reporting/trackers/gitea/gitea.go
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporting/trackers/github/github.go
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporting/trackers/gitlab/gitlab.go
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporting/trackers/jira/jira.go
Expand Up @@ -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) {
Expand Down

0 comments on commit 6067b78

Please sign in to comment.