55 scan_mode :
66 description : " Scan mode: full | diff"
77 required : false
8- default : " full "
8+ default : " diff "
99 gitleaks_version :
1010 description : " Gitleaks version to install"
1111 required : false
9393 exit 0
9494 fi
9595
96- mapfile -t FILES < <(git diff --name-only --diff-filter=AMR "${BASE_SHA}... ${HEAD_SHA}")
96+ mapfile -t FILES < <(git diff --name-only --diff-filter=AMR "${BASE_SHA}" " ${HEAD_SHA}")
9797 if (( ${#FILES[@]} == 0 )); then
9898 echo "No changed files."
9999 echo "src_dir=" >> "$GITHUB_OUTPUT"
@@ -112,7 +112,7 @@ runs:
112112 echo '{}' > "$PATCH_JSON"
113113
114114 while IFS= read -r file; do
115- HUNKS="$(git diff --unified=0 "${BASE_SHA}... ${HEAD_SHA}" -- "$file" \
115+ HUNKS="$(git diff --unified=0 "${BASE_SHA}" " ${HEAD_SHA}" -- "$file" \
116116 | awk '/^@@/ {print}' \
117117 | sed -n 's/.*+\([0-9]\+\),\([0-9]\+\).*/\1 \2/p')"
118118
@@ -163,8 +163,6 @@ runs:
163163 - name : Filter findings by added lines (patch)
164164 if : ${{ inputs.scan_mode == 'diff' }}
165165 shell : bash
166- env :
167- SRC_DIR : ${{ steps.prpatch.outputs.src_dir }}
168166 run : |
169167 set -euo pipefail
170168 PATCH_MAP_PATH="${{ steps.prpatch.outputs.patch_map }}"
@@ -176,19 +174,16 @@ runs:
176174 fi
177175
178176 MAP_JSON="$(cat "${PATCH_MAP_PATH}")"
179- SRC_PREFIX="${SRC_DIR%/}/"
180177
181- jq --argjson map "${MAP_JSON}" --arg src "${SRC_PREFIX}" '
178+ jq --argjson map "${MAP_JSON}" '
182179 def arr: if type=="object" and has("findings") then .findings
183180 elif type=="array" then . else [] end;
184- def strip($p; s): if s|startswith($p) then s[($p|length):] else s end;
185-
186181 arr
187182 | map(
188183 . as $f
189- | (strip($src; ($ f.File // $f.file // $f.Target // $f.Location.File // ""))) as $rel
184+ | ($ f.File // $f.file // $f.Target // $f.Location.File // "") as $file
190185 | ($f.StartLine // $f.Line // $f.Location.StartLine // 0) as $line
191- | if ($map[$rel ] // [] ) as $ranges
186+ | if ($map[$file ] // empty ) as $ranges
192187 | any($ranges[]; $line >= .[0] and $line <= .[1])
193188 then $f else empty end
194189 )
0 commit comments