From f1fa9480c40f63aae17974aa11d1b9d23c20f582 Mon Sep 17 00:00:00 2001 From: jperezde Date: Thu, 9 Jan 2025 15:09:04 +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 8595a46175..b0c59218ce 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 @@ -236,8 +236,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 138e9c61a4..2a78e65207 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}