From a944ac8e8cc6e39c8ff58665ea2b8c5bf98772c5 Mon Sep 17 00:00:00 2001 From: Maitray Shah Date: Mon, 12 Dec 2022 10:19:00 -0800 Subject: [PATCH 1/2] Report AutoFix Results --- lib/salus/report.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/salus/report.rb b/lib/salus/report.rb index 28682692..d06edfbc 100644 --- a/lib/salus/report.rb +++ b/lib/salus/report.rb @@ -270,6 +270,17 @@ def to_cyclonedx(config = {}) bugsnag_notify(e.class.to_s + " " + e.message + "\nBuild Info:" + @builds.to_s) end + def to_auto_fix + auto_fixes = {} + file_names = ["yarn-autofixed.lock", "package-autofixed.json"] + file_names.each do |file_name| + if File.exist?("/home/repo/#{file_name}") + auto_fixes[file_name] = File.read("/home/repo/#{file_name}") + end + end + JSON.pretty_generate(auto_fixes) + end + def publish_report(directive) # First create the string for the report. uri = directive['uri'] @@ -283,6 +294,7 @@ def publish_report(directive) when 'sarif_diff' then to_sarif_diff when 'sarif_diff_full' then to_full_sarif_diff when 'cyclonedx-json' then to_cyclonedx(directive['cyclonedx_options'] || {}) + when 'auto_fix' then to_auto_fix else raise ExportReportError, "unknown report format #{directive['format']}" end @@ -405,9 +417,11 @@ def report_body(config) to_full_sarif_diff when 'cyclonedx-json' to_cyclonedx(config['cyclonedx_options'] || {}) + when 'auto_fix' + to_auto_fix end - if %w[json sarif sarif_diff sarif_diff_full cyclonedx-json].include?(config['format']) + if %w[json sarif sarif_diff sarif_diff_full cyclonedx-json auto_fix].include?(config['format']) body = JSON.parse(body) return JSON.pretty_generate(report_body_hash(config, body)) end From 1da6ed194f7285d7aec85f9435a372197fb4a1bb Mon Sep 17 00:00:00 2001 From: Maitray Shah Date: Mon, 12 Dec 2022 10:29:17 -0800 Subject: [PATCH 2/2] rubocop fix --- lib/salus/report.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/salus/report.rb b/lib/salus/report.rb index d06edfbc..bf282aa1 100644 --- a/lib/salus/report.rb +++ b/lib/salus/report.rb @@ -418,10 +418,12 @@ def report_body(config) when 'cyclonedx-json' to_cyclonedx(config['cyclonedx_options'] || {}) when 'auto_fix' - to_auto_fix + to_auto_fix end - if %w[json sarif sarif_diff sarif_diff_full cyclonedx-json auto_fix].include?(config['format']) + if %w[json sarif sarif_diff sarif_diff_full cyclonedx-json auto_fix].include?( + config['format'] + ) body = JSON.parse(body) return JSON.pretty_generate(report_body_hash(config, body)) end