Skip to content

Commit fe6bb51

Browse files
🐛 fix: use contains() for pull_request event detection in Sonar workflow (#611)
Change pull_request event detection from exact equality to contains() to properly handle both pull_request and pull_request_target events. Previously, the workflow used `github.event_name == 'pull_request'` which failed to match pull_request_target events, causing the sonar.pullrequest.key parameter to not be set for PRs targeting main. This change makes the Sonar workflow consistent with the Checkmarx workflow which already uses contains() for event detection. Affected configurations: - Default sonar-scanner (line 72) - dotnet scanner (line 108) - maven scanner (line 145)
1 parent 80e5f99 commit fe6bb51

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

.github/workflows/_sonar.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
env:
7070
SONAR_TOKEN: ${{ steps.get-kv-secrets.outputs.SONAR-TOKEN }}
7171
SONAR_ARGS: >-
72-
${{ github.event_name == 'pull_request' && format('"-Dsonar.pullrequest.key={0}"', github.event.pull_request.number) || '' }}
72+
${{ contains(github.event_name, 'pull_request') && format('"-Dsonar.pullrequest.key={0}"', github.event.pull_request.number) || '' }}
7373
${{ inputs.sonar-test-inclusions != '' && format('"-Dsonar.test.inclusions={0}"', inputs.sonar-test-inclusions) || '' }}
7474
${{ inputs.sonar-exclusions != '' && format('"-Dsonar.exclusions={0}"', inputs.sonar-exclusions) || '' }}
7575
${{ inputs.sonar-sources != '' && format('"-Dsonar.sources={0}"', inputs.sonar-sources) || '' }}
@@ -105,7 +105,7 @@ jobs:
105105
_SONAR_EXCLUSIONS: ${{ inputs.sonar-exclusions }}
106106
_SONAR_SOURCES: ${{ inputs.sonar-sources }}
107107
_SONAR_TESTS: ${{ inputs.sonar-tests }}
108-
_PULL_REQUEST_KEY: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || '' }}
108+
_PULL_REQUEST_KEY: ${{ contains(github.event_name, 'pull_request') && github.event.pull_request.number || '' }}
109109
run: |
110110
set -euo pipefail
111111
ARGS=()
@@ -142,7 +142,7 @@ jobs:
142142
_SONAR_EXCLUSIONS: ${{ inputs.sonar-exclusions }}
143143
_SONAR_SOURCES: ${{ inputs.sonar-sources }}
144144
_SONAR_TESTS: ${{ inputs.sonar-tests }}
145-
_PULL_REQUEST_KEY: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || '' }}
145+
_PULL_REQUEST_KEY: ${{ contains(github.event_name, 'pull_request') && github.event.pull_request.number || '' }}
146146
run: |
147147
set -euo pipefail
148148
ARGS=()

0 commit comments

Comments
 (0)