Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #65 from fberthereau/output_github_action
Browse files Browse the repository at this point in the history
Take input format for github action output
  • Loading branch information
fabpot authored Sep 30, 2022
2 parents 9150955 + 8bf971f commit b3b8eca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {

if os.Getenv("GITHUB_WORKSPACE") != "" {
// inside a Github action, export vulns
if output, err := security.Format(vulns, "raw_json"); err != nil {
if output, err := security.Format(vulns, "raw_json"); err == nil {
fmt.Printf("::set-output name=vulns::%s", output)
}
}
Expand Down
12 changes: 9 additions & 3 deletions security/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ func Format(vulns *Vulnerabilities, format string) ([]byte, error) {
} else if format == "text" || format == "txt" || format == "markdown" || format == "md" {
return ToMarkdown(vulns), nil
} else if format == "json" {
return ToJSON(vulns)
return ToJSON(vulns, true)
} else if format == "raw_json" {
return ToJSON(vulns, false)
} else if format == "junit" {
return ToJunit(vulns)
} else if format == "yaml" || format == "yml" {
Expand Down Expand Up @@ -78,8 +80,12 @@ func ToMarkdown(vulns *Vulnerabilities) []byte {
}

// ToJSON outputs vulnerabilities as JSON
func ToJSON(vulns *Vulnerabilities) ([]byte, error) {
return json.MarshalIndent(vulns, "", " ")
func ToJSON(vulns *Vulnerabilities, prettify bool) ([]byte, error) {
if prettify {
return json.MarshalIndent(vulns, "", " ")
}

return json.Marshal(vulns)
}

// ToYAML outputs vulnerabilities as YAML
Expand Down

0 comments on commit b3b8eca

Please sign in to comment.