Skip to content

Commit

Permalink
feat(report): export ExperimentalModifiedFindings in JSON
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Aug 26, 2024
1 parent 05a8297 commit 408c869
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 9 additions & 2 deletions pkg/report/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (

// JSONWriter implements result Writer
type JSONWriter struct {
Output io.Writer
ListAllPkgs bool
Output io.Writer
ListAllPkgs bool
ShowSuppressed bool
}

// Write writes the results in JSON format
Expand All @@ -26,6 +27,12 @@ func (jw JSONWriter) Write(_ context.Context, report types.Report) error {
report.Results[i].Packages = nil
}
}
if !jw.ShowSuppressed {
// Delete suppressed findings
for i := range report.Results {
report.Results[i].ModifiedFindings = nil
}
}
report.Results = lo.Filter(report.Results, func(r types.Result, _ int) bool {
return r.Target != "" || !r.IsEmpty()
})
Expand Down
5 changes: 3 additions & 2 deletions pkg/report/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ func Write(ctx context.Context, report types.Report, option flag.Options) (err e
}
case types.FormatJSON:
writer = &JSONWriter{
Output: output,
ListAllPkgs: option.ListAllPkgs,
Output: output,
ListAllPkgs: option.ListAllPkgs,
ShowSuppressed: option.ShowSuppressed,
}
case types.FormatGitHub:
writer = &github.Writer{
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ type Result struct {

// ModifiedFindings holds a list of findings that have been modified from their original state.
// This can include vulnerabilities that have been marked as ignored, not affected, or have had
// their severity adjusted. It is currently available only in the table format.
ModifiedFindings []ModifiedFinding `json:"-"`
// their severity adjusted. It's still in an experimental stage and may change in the future.
ModifiedFindings []ModifiedFinding `json:"ExperimentalModifiedFindings,omitempty"`
}

func (r *Result) IsEmpty() bool {
Expand Down

0 comments on commit 408c869

Please sign in to comment.