From dc1d1352a1ae7234b0181e77b26216f11e945918 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 17 Jan 2026 16:28:39 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8[Enhancement]:=20Add=20GitHub=20event?= =?UTF-8?q?=20data=20handling=20for=20pull=20request=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 58e6853..8271cc6 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -192,17 +192,46 @@ $settings | Add-Member -MemberType NoteProperty -Name WorkingDirectory -Value $w # Calculate job run conditions LogGroup 'Calculate Job Run Conditions:' { # Common conditions + $eventData = $null + try { + $eventData = Get-GitHubEventData -ErrorAction Stop + } catch { + if (-not [string]::IsNullOrEmpty($env:GITHUB_EVENT_PATH) -and (Test-Path -Path $env:GITHUB_EVENT_PATH)) { + $eventData = Get-Content -Path $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json + } + } + + LogGroup 'GitHub Event Data' { + if ($null -ne $eventData) { + Write-Host ($eventData | ConvertTo-Json -Depth 10 | Out-String) + } else { + Write-Host 'No event data available.' + } + } + + $pullRequestAction = if ($null -ne $eventData.action) { + $eventData.action + } else { + $env:GITHUB_EVENT_ACTION + } + + $pullRequestIsMerged = if ($null -ne $eventData.pull_request -and $null -ne $eventData.pull_request.merged) { + [bool]$eventData.pull_request.merged + } else { + $false + } + Write-Host 'GitHub event inputs:' [pscustomobject]@{ GITHUB_EVENT_NAME = $env:GITHUB_EVENT_NAME - GITHUB_EVENT_ACTION = $env:GITHUB_EVENT_ACTION - GITHUB_EVENT_PULL_REQUEST_MERGED = $env:GITHUB_EVENT_PULL_REQUEST_MERGED + GITHUB_EVENT_ACTION = $pullRequestAction + GITHUB_EVENT_PULL_REQUEST_MERGED = $pullRequestIsMerged } | Format-List | Out-String $isPR = $env:GITHUB_EVENT_NAME -eq 'pull_request' - $isOpenOrUpdatedPR = $isPR -and $env:GITHUB_EVENT_ACTION -in @('opened', 'reopened', 'synchronize') - $isAbandonedPR = $isPR -and $env:GITHUB_EVENT_ACTION -eq 'closed' -and $env:GITHUB_EVENT_PULL_REQUEST_MERGED -ne 'true' - $isMergedPR = $isPR -and $env:GITHUB_EVENT_ACTION -eq 'closed' -and $env:GITHUB_EVENT_PULL_REQUEST_MERGED -eq 'true' + $isOpenOrUpdatedPR = $isPR -and $pullRequestAction -in @('opened', 'reopened', 'synchronize') + $isAbandonedPR = $isPR -and $pullRequestAction -eq 'closed' -and $pullRequestIsMerged -ne $true + $isMergedPR = $isPR -and $pullRequestAction -eq 'closed' -and $pullRequestIsMerged -eq $true $isNotAbandonedPR = -not $isAbandonedPR [pscustomobject]@{