Skip to content

Commit 6e5cf96

Browse files
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. Made-with: Cursor
1 parent bd0a4d1 commit 6e5cf96

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

.github/workflows/reusable-trufflehog.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ 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'
4848
run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
4949

50+
- name: Fetch base and head commits (merge_group)
51+
if: github.event_name == 'merge_group'
52+
run: git fetch --depth=1 origin ${{ github.event.merge_group.base_sha }} ${{ github.event.merge_group.head_sha }}
53+
5054
- name: Remove persisted credentials
5155
run: git config --unset-all http.https://github.com/.extraheader
5256

@@ -97,10 +101,15 @@ jobs:
97101
set +e
98102
echo "[]" > results.json
99103
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
104+
if [[ "${{ github.event_name }}" == "pull_request" ]] || [[ "${{ github.event_name }}" == "merge_group" ]]; then
105+
# PR / merge queue: scan only paths that differ from base..head (not the entire checkout)
106+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
107+
echo "Scanning changed files in PR..."
108+
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} > changed-files.txt
109+
else
110+
echo "Scanning changed files in merge group..."
111+
git diff --name-only ${{ github.event.merge_group.base_sha }} ${{ github.event.merge_group.head_sha }} > changed-files.txt
112+
fi
104113
105114
if [[ -s changed-files.txt ]]; then
106115
while IFS= read -r file; do
@@ -124,7 +133,7 @@ jobs:
124133
echo "No files changed"
125134
fi
126135
else
127-
# Push to main: Scan current filesystem
136+
# push to main (and any other events): full filesystem scan
128137
echo "Scanning current filesystem..."
129138
trufflehog filesystem . --exclude-paths /tmp/trufflehog-exclude.txt --concurrency 16 --json --no-update --results=verified,unverified > results.ndjson || true
130139
fi

0 commit comments

Comments
 (0)