Skip to content

Commit 58d80d7

Browse files
🩹 [Patch]: Correct how we get pull request info (#3)
This release updates the logic for processing GitHub event data in `scripts/main.ps1`, making the workflow more robust and accurate when handling pull request events. The main improvements focus on how event data is retrieved and how pull request states are determined. **Event Data Handling Improvements:** * Added logic to retrieve and parse GitHub event data more reliably, including a fallback to read and parse the event file if the primary method fails. * Introduced a dedicated logging group to output the full event data for easier debugging. **Pull Request State Calculation Enhancements:** * Refactored how pull request action and merged status are determined, using parsed event data instead of relying solely on environment variables. * Updated the conditions for identifying open/updated, abandoned, and merged pull requests to use the improved event data logic, ensuring more accurate state detection.
1 parent 9c811d0 commit 58d80d7

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

scripts/main.ps1

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,46 @@ $settings | Add-Member -MemberType NoteProperty -Name WorkingDirectory -Value $w
192192
# Calculate job run conditions
193193
LogGroup 'Calculate Job Run Conditions:' {
194194
# Common conditions
195+
$eventData = $null
196+
try {
197+
$eventData = Get-GitHubEventData -ErrorAction Stop
198+
} catch {
199+
if (-not [string]::IsNullOrEmpty($env:GITHUB_EVENT_PATH) -and (Test-Path -Path $env:GITHUB_EVENT_PATH)) {
200+
$eventData = Get-Content -Path $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
201+
}
202+
}
203+
204+
LogGroup 'GitHub Event Data' {
205+
if ($null -ne $eventData) {
206+
Write-Host ($eventData | ConvertTo-Json -Depth 10 | Out-String)
207+
} else {
208+
Write-Host 'No event data available.'
209+
}
210+
}
211+
212+
$pullRequestAction = if ($null -ne $eventData.action) {
213+
$eventData.action
214+
} else {
215+
$env:GITHUB_EVENT_ACTION
216+
}
217+
218+
$pullRequestIsMerged = if ($null -ne $eventData.pull_request -and $null -ne $eventData.pull_request.merged) {
219+
[bool]$eventData.pull_request.merged
220+
} else {
221+
$false
222+
}
223+
195224
Write-Host 'GitHub event inputs:'
196225
[pscustomobject]@{
197226
GITHUB_EVENT_NAME = $env:GITHUB_EVENT_NAME
198-
GITHUB_EVENT_ACTION = $env:GITHUB_EVENT_ACTION
199-
GITHUB_EVENT_PULL_REQUEST_MERGED = $env:GITHUB_EVENT_PULL_REQUEST_MERGED
227+
GITHUB_EVENT_ACTION = $pullRequestAction
228+
GITHUB_EVENT_PULL_REQUEST_MERGED = $pullRequestIsMerged
200229
} | Format-List | Out-String
201230

202231
$isPR = $env:GITHUB_EVENT_NAME -eq 'pull_request'
203-
$isOpenOrUpdatedPR = $isPR -and $env:GITHUB_EVENT_ACTION -in @('opened', 'reopened', 'synchronize')
204-
$isAbandonedPR = $isPR -and $env:GITHUB_EVENT_ACTION -eq 'closed' -and $env:GITHUB_EVENT_PULL_REQUEST_MERGED -ne 'true'
205-
$isMergedPR = $isPR -and $env:GITHUB_EVENT_ACTION -eq 'closed' -and $env:GITHUB_EVENT_PULL_REQUEST_MERGED -eq 'true'
232+
$isOpenOrUpdatedPR = $isPR -and $pullRequestAction -in @('opened', 'reopened', 'synchronize')
233+
$isAbandonedPR = $isPR -and $pullRequestAction -eq 'closed' -and $pullRequestIsMerged -ne $true
234+
$isMergedPR = $isPR -and $pullRequestAction -eq 'closed' -and $pullRequestIsMerged -eq $true
206235
$isNotAbandonedPR = -not $isAbandonedPR
207236

208237
[pscustomobject]@{

0 commit comments

Comments
 (0)