Skip to content

Commit c017ec9

Browse files
Add target branch detection for default branch comparison
1 parent 3b93ae6 commit c017ec9

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

scripts/main.ps1

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,37 @@ LogGroup 'Calculate Job Run Conditions:' {
231231
$false
232232
}
233233

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+
}
256+
234257
Write-Host 'GitHub event inputs:'
235258
[pscustomobject]@{
236259
GITHUB_EVENT_NAME = $env:GITHUB_EVENT_NAME
237260
GITHUB_EVENT_ACTION = $pullRequestAction
238261
GITHUB_EVENT_PULL_REQUEST_MERGED = $pullRequestIsMerged
262+
TargetBranch = $targetBranch
263+
DefaultBranch = $defaultBranch
264+
IsTargetDefaultBranch = $isTargetDefaultBranch
239265
} | Format-List | Out-String
240266

241267
$isPR = $env:GITHUB_EVENT_NAME -eq 'pull_request'
@@ -267,13 +293,14 @@ LogGroup 'Calculate Job Run Conditions:' {
267293
}
268294

269295
[pscustomobject]@{
270-
isPR = $isPR
271-
isOpenOrUpdatedPR = $isOpenOrUpdatedPR
272-
isAbandonedPR = $isAbandonedPR
273-
isMergedPR = $isMergedPR
274-
isNotAbandonedPR = $isNotAbandonedPR
275-
shouldPrerelease = $shouldPrerelease
276-
ReleaseType = $releaseType
296+
isPR = $isPR
297+
isOpenOrUpdatedPR = $isOpenOrUpdatedPR
298+
isAbandonedPR = $isAbandonedPR
299+
isMergedPR = $isMergedPR
300+
isNotAbandonedPR = $isNotAbandonedPR
301+
isTargetDefaultBranch = $isTargetDefaultBranch
302+
shouldPrerelease = $shouldPrerelease
303+
ReleaseType = $releaseType
277304
} | Format-List | Out-String
278305
}
279306

0 commit comments

Comments
 (0)