From f716d77ab0eb4dc7726ef17e30deff902517180a Mon Sep 17 00:00:00 2001 From: jperezde Date: Thu, 9 Jan 2025 14:16:46 +0100 Subject: [PATCH] sast-snyk-check: added fix for generating stats with ignore files Resolves: https://issues.redhat.com/browse/OSH-795 The jq command returned null when the scan ignored files and there were findings. That null value is now converted into 0 --- task/sast-snyk-check-oci-ta/0.3/sast-snyk-check-oci-ta.yaml | 4 ++-- task/sast-snyk-check/0.3/sast-snyk-check.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/task/sast-snyk-check-oci-ta/0.3/sast-snyk-check-oci-ta.yaml b/task/sast-snyk-check-oci-ta/0.3/sast-snyk-check-oci-ta.yaml index 4efe9c8963..a214fc0f51 100644 --- a/task/sast-snyk-check-oci-ta/0.3/sast-snyk-check-oci-ta.yaml +++ b/task/sast-snyk-check-oci-ta/0.3/sast-snyk-check-oci-ta.yaml @@ -232,8 +232,8 @@ spec: # Generation of scan stats - total_files=$(jq '[.runs[0].properties.coverage[].files] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) - supported_files=$(jq '[.runs[0].properties.coverage[] | select(.type == "SUPPORTED") | .files] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) + total_files=$(jq '[.runs[0].properties.coverage[].files // 0] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) + supported_files=$(jq '[.runs[0].properties.coverage[] | select(.type == "SUPPORTED") | .files // 0] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) # We make sure the values are 0 if no supported/total files are found total_files=${total_files:-0} diff --git a/task/sast-snyk-check/0.3/sast-snyk-check.yaml b/task/sast-snyk-check/0.3/sast-snyk-check.yaml index 4ec2e8da4f..13eb64901f 100644 --- a/task/sast-snyk-check/0.3/sast-snyk-check.yaml +++ b/task/sast-snyk-check/0.3/sast-snyk-check.yaml @@ -213,8 +213,8 @@ spec: # Generation of scan stats - total_files=$(jq '[.runs[0].properties.coverage[].files] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) - supported_files=$(jq '[.runs[0].properties.coverage[] | select(.type == "SUPPORTED") | .files] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) + total_files=$(jq '[.runs[0].properties.coverage[].files // 0] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) + supported_files=$(jq '[.runs[0].properties.coverage[] | select(.type == "SUPPORTED") | .files // 0] | add' "${SOURCE_CODE_DIR}"/sast_snyk_check_out.json) # We make sure the values are 0 if no supported/total files are found total_files=${total_files:-0}