Skip to content

Commit

Permalink
add an option to write sarif report
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoberezhniy committed May 6, 2024
1 parent 08451eb commit 2717a4f
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ for opt
do
case "$opt" in
-S=*|--severity=*)
INPUT_SEVERITY="${opt#*=}"
shift
;;
INPUT_SEVERITY="${opt#*=}"
shift
;;
-S|--severity)
# shellcheck disable=SC2034
INPUT_SEVERITY="$2"
# shellcheck disable=SC2016
shift 2 || { echo 'option `--severity` requires an argument SEVERITY' >&2; exit 1; }
;;
# shellcheck disable=SC2034
INPUT_SEVERITY="$2"
# shellcheck disable=SC2016
shift 2 || { echo 'option `--severity` requires an argument SEVERITY' >&2; exit 1; }
;;
-x|--external-sources)
# shellcheck disable=SC2034
INPUT_EXTERNAL_SOURCES=y
shift
;;
# shellcheck disable=SC2034
INPUT_EXTERNAL_SOURCES=y
shift
;;
--sarif)
INPUT_WRITE_SARIF=y
shift
;;
esac
done

Expand Down Expand Up @@ -73,6 +77,17 @@ echo
evaluate_and_print_defects
exit_status=$?

if is_true "${INPUT_WRITE_SARIF}"; then
shellcheck_version=$(get_shellcheck_version)
csgrep \
--strip-path-prefix './' \
--mode=sarif \
--set-scan-prop='tool:ShellCheck' \
--set-scan-prop="tool-version:${shellcheck_version}" \
--set-scan-prop='tool-url:https://www.shellcheck.net/wiki/' \
"${WORK_DIR}defects.log" > output.sarif
fi

summary

exit ${exit_status}

0 comments on commit 2717a4f

Please sign in to comment.