Skip to content

Commit 2714999

Browse files
Refactor job run condition calculations for improved clarity and efficiency
1 parent 0cf689b commit 2714999

1 file changed

Lines changed: 8 additions & 54 deletions

File tree

scripts/main.ps1

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -195,64 +195,18 @@ $settings | Add-Member -MemberType NoteProperty -Name WorkingDirectory -Value $w
195195

196196
# Calculate job run conditions
197197
LogGroup 'Calculate Job Run Conditions:' {
198-
# Common conditions
199-
$eventData = $null
200-
try {
201-
$eventData = Get-GitHubEventData -ErrorAction Stop
202-
} catch {
203-
if (-not [string]::IsNullOrEmpty($env:GITHUB_EVENT_PATH) -and (Test-Path -Path $env:GITHUB_EVENT_PATH)) {
204-
$eventData = Get-Content -Path $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
205-
}
206-
}
198+
$eventData = Get-GitHubEventData -ErrorAction Stop
207199

208200
LogGroup 'GitHub Event Data' {
209-
if ($null -ne $eventData) {
210-
Write-Host ($eventData | ConvertTo-Json -Depth 10 | Out-String)
211-
} else {
212-
Write-Host 'No event data available.'
213-
}
201+
$eventData | ConvertTo-Json -Depth 10 | Out-String
214202
}
215203

216-
$pullRequestAction = if ($null -ne $eventData.Action) {
217-
$eventData.Action
218-
} else {
219-
$env:GITHUB_EVENT_ACTION
220-
}
221-
222-
$pullRequest = if ($null -ne $eventData.PullRequest) {
223-
$eventData.PullRequest
224-
} else {
225-
$null
226-
}
227-
228-
$pullRequestIsMerged = if ($null -ne $pullRequest -and $null -ne $pullRequest.Merged) {
229-
[bool]$pullRequest.Merged
230-
} else {
231-
$false
232-
}
233-
234-
# Get target branch (the branch the PR is merging into)
235-
$targetBranch = if ($null -ne $pullRequest -and $null -ne $pullRequest.Base.Ref) {
236-
$pullRequest.Base.Ref
237-
} else {
238-
$null
239-
}
240-
241-
# Get default branch from repository info
242-
$defaultBranch = if ($null -ne $eventData.Repository.DefaultBranch) {
243-
$eventData.Repository.DefaultBranch
244-
} elseif ($null -ne $eventData.Repository.default_branch) {
245-
$eventData.Repository.default_branch
246-
} else {
247-
$env:GITHUB_DEFAULT_BRANCH
248-
}
249-
250-
# Check if target branch is the default branch
251-
$isTargetDefaultBranch = if ($null -ne $targetBranch -and $null -ne $defaultBranch) {
252-
$targetBranch -eq $defaultBranch
253-
} else {
254-
$false
255-
}
204+
$pullRequestAction = $eventData.Action
205+
$pullRequest = $eventData.PullRequest
206+
$pullRequestIsMerged = $pullRequest.Merged
207+
$targetBranch = $pullRequest.Base.Ref
208+
$defaultBranch = $eventData.Repository.default_branch
209+
$isTargetDefaultBranch = $targetBranch -eq $defaultBranch
256210

257211
Write-Host 'GitHub event inputs:'
258212
[pscustomobject]@{

0 commit comments

Comments
 (0)