55  scan_mode :
66    description : " Scan mode: full | diff" 
77    required : false 
8-     default : " diff " 
8+     default : " full " 
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,6 +163,8 @@ runs:
163163name : 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 }} 
166168      run : | 
167169        set -euo pipefail 
168170        PATCH_MAP_PATH="${{ steps.prpatch.outputs.patch_map }}" 
@@ -174,16 +176,19 @@ runs:
174176        fi 
175177
176178        MAP_JSON="$(cat "${PATCH_MAP_PATH}")" 
179+         SRC_PREFIX="${SRC_DIR%/}/" 
177180
178-         jq --argjson map "${MAP_JSON}" ' 
181+         jq --argjson map "${MAP_JSON}" --arg src "${SRC_PREFIX}"  ' 
179182          def arr: if type=="object" and has("findings") then .findings 
180183                   elif type=="array" then . else [] end; 
184+           def strip($p; s): if s|startswith($p) then s[($p|length):] else s end; 
185+ 
181186          arr 
182187          | map( 
183188              . as $f 
184-               | ($ f.File // $f.file // $f.Target // $f.Location.File // "") as $file  
189+               | (strip($src; ($ f.File // $f.file // $f.Target // $f.Location.File // "")))  as $rel  
185190              | ($f.StartLine // $f.Line // $f.Location.StartLine // 0) as $line 
186-               | if ($map[$file ] // empty ) as $ranges 
191+               | if ($map[$rel ] // [] ) as $ranges 
187192                | any($ranges[]; $line >= .[0] and $line <= .[1]) 
188193                then $f else empty end 
189194            ) 
0 commit comments