44
55set -euo pipefail
66
7- # Pre-commit git hook to scan for secrets hard-coded in the codebase. This is a
8- # gitleaks command wrapper. It will run gitleaks natively if it is installed,
9- # otherwise it will run it in a Docker container .
7+ # Pre-commit git hook to scan for TODO markers in the codebase.
8+ # It checks repository files for TODO entries and fails when a TODO does not
9+ # include a Jira ticket reference .
1010#
1111# Usage:
12- # $ [options] ./scan-secrets .sh
12+ # $ [options] ./check-todos .sh
1313#
1414# Options:
1515# check=all # check all files in the repository
@@ -19,8 +19,8 @@ set -euo pipefail
1919# VERBOSE=true # Show all the executed commands, default is 'false'
2020#
2121# Exit codes:
22- # 0 - No Todos
23- # 1 - Todos found or error encountered
22+ # 0 - No TODOs without a Jira ticket reference
23+ # 1 - TODOs without a Jira ticket reference found, or error encountered
2424# 126 - Unknown flag
2525
2626# ==============================================================================
@@ -93,7 +93,7 @@ function build_exclude_args() {
9393function search_todos() {
9494 local mode=" $1 "
9595 shift # Shift positional parameters so $@ contains only exclude_args
96- local exclude_args=(" $@ " )
96+ local -a exclude_args=(" $@ " )
9797 local todos=" "
9898
9999 local files
@@ -109,7 +109,7 @@ function search_todos() {
109109 for ex in " ${exclude_args[@]} " ; do
110110 if [[ " $ex " == --exclude* ]]; then
111111 pattern=${ex# --exclude=}
112- [[ " $file " == $pattern ]] && skip=true && break
112+ [[ " $file " == " $pattern " ]] && skip=true && break
113113 fi
114114 done
115115
@@ -150,8 +150,10 @@ function filter_todos_with_valid_jira_ticket() {
150150
151151function print_output() {
152152 local todos=" $1 "
153- local exclude_args=" $2 "
154- local todo_count=$( line_count " $todos " )
153+ shift
154+ local -a exclude_args=(" $@ " )
155+ local todo_count
156+ todo_count=$( line_count " $todos " )
155157
156158 echo " TODO Check Configuration:"
157159 echo " ========================================="
@@ -171,7 +173,7 @@ function print_output() {
171173 fi
172174
173175 if is-arg-true " ${VERBOSE:- false} " ; then
174- echo " Grep Exclude Args: $exclude_args "
176+ echo " Grep Exclude Args: ${ exclude_args[*]} "
175177 fi
176178
177179 echo -e " \n========================================="
@@ -184,8 +186,10 @@ function print_output() {
184186 echo " No TODOs found."
185187 fi
186188
187- local results=$( filter_todos_with_valid_jira_ticket " $todos " )
188- local results_count=$( line_count " $results " )
189+ local results
190+ results=$( filter_todos_with_valid_jira_ticket " $todos " )
191+ local results_count
192+ results_count=$( line_count " $results " )
189193
190194 echo -e " \n========================================="
191195 echo " TODOs without a Jira ticket: $results_count "
@@ -204,9 +208,11 @@ function main() {
204208 cd " $( git rev-parse --show-toplevel) "
205209
206210 local check_mode=" ${check:- working-tree-changes} "
207- local exclude_args=$( build_exclude_args)
208- local todos=$( search_todos " $check_mode " $exclude_args )
209- print_output " $todos " " $exclude_args "
211+ local -a exclude_args
212+ read -r -a exclude_args <<< " $(build_exclude_args)"
213+ local todos
214+ todos=$( search_todos " $check_mode " " ${exclude_args[@]} " )
215+ print_output " $todos " " ${exclude_args[@]} "
210216}
211217
212218# ==============================================================================
0 commit comments