Skip to content

Commit a7ed27a

Browse files
fix(trufflehog): scope merge_group scans to diff like pull_request (#141)
* fix(trufflehog): scope merge_group scans to diff like pull_request Merge queue runs use github.event_name merge_group, which previously fell through to trufflehog filesystem . and scanned the entire repo. Fetch merge_group base/head SHAs and git diff --name-only to match PR behavior.
1 parent bd0a4d1 commit a7ed27a

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

.github/workflows/reusable-trufflehog.yml

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,19 @@ jobs:
4343
fetch-depth: 1
4444
persist-credentials: true
4545

46-
- name: Fetch base and head commits
46+
- name: Fetch base and head commits (pull_request)
4747
if: github.event_name == 'pull_request'
48-
run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
48+
env:
49+
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
50+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
51+
run: git fetch --depth=1 origin "$PR_BASE_SHA" "$PR_HEAD_SHA"
52+
53+
- name: Fetch base and head commits (merge_group)
54+
if: github.event_name == 'merge_group'
55+
env:
56+
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
57+
MERGE_GROUP_HEAD_SHA: ${{ github.event.merge_group.head_sha }}
58+
run: git fetch --depth=1 origin "$MERGE_GROUP_BASE_SHA" "$MERGE_GROUP_HEAD_SHA"
4959

5060
- name: Remove persisted credentials
5161
run: git config --unset-all http.https://github.com/.extraheader
@@ -93,14 +103,24 @@ jobs:
93103
94104
- name: Scan for secrets
95105
id: scan
106+
env:
107+
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
108+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
109+
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
110+
MERGE_GROUP_HEAD_SHA: ${{ github.event.merge_group.head_sha }}
96111
run: |
97112
set +e
98113
echo "[]" > results.json
99114
100-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
101-
# PR: Scan only changed files (using two-dot diff with explicit base SHA)
102-
echo "Scanning changed files in PR..."
103-
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > changed-files.txt
115+
if [[ "${{ github.event_name }}" == "pull_request" ]] || [[ "${{ github.event_name }}" == "merge_group" ]]; then
116+
# PR / merge queue: scan only paths that differ from base..head (not the entire checkout)
117+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
118+
echo "Scanning changed files in PR..."
119+
git diff --name-only "$PR_BASE_SHA" "$PR_HEAD_SHA" > changed-files.txt
120+
else
121+
echo "Scanning changed files in merge group..."
122+
git diff --name-only "$MERGE_GROUP_BASE_SHA" "$MERGE_GROUP_HEAD_SHA" > changed-files.txt
123+
fi
104124
105125
if [[ -s changed-files.txt ]]; then
106126
while IFS= read -r file; do
@@ -124,7 +144,7 @@ jobs:
124144
echo "No files changed"
125145
fi
126146
else
127-
# Push to main: Scan current filesystem
147+
# push to main (and any other events): full filesystem scan
128148
echo "Scanning current filesystem..."
129149
trufflehog filesystem . --exclude-paths /tmp/trufflehog-exclude.txt --concurrency 16 --json --no-update --results=verified,unverified > results.ndjson || true
130150
fi

0 commit comments

Comments
 (0)