Skip to content

Commit 2133e2d

Browse files
Address Copilot review: document \ return on non-PR; add Get-GitHubPullRequest coverage
1 parent a1a469e commit 2133e2d

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

scripts/Resolve-PSModuleVersion.Helpers.psm1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,14 @@ function Get-GitHubPullRequest {
126126
Reads and validates the GitHub pull request from the event payload.
127127
128128
.DESCRIPTION
129-
Loads the GitHub event from the input override or from the event path file,
130-
then validates and extracts pull request data.
129+
Loads the GitHub event from the input override or from the event path file. On a
130+
pull_request event it returns the pull request head ref and labels. On any other
131+
event (for example workflow_dispatch or schedule) there is no pull request, so it
132+
returns $null and the caller resolves the current version without a version bump.
131133
132134
.OUTPUTS
133-
PSCustomObject with HeadRef and Labels properties.
135+
PSCustomObject with HeadRef and Labels properties for a pull_request event, or
136+
$null when the event has no pull request (non-PR events).
134137
135138
.EXAMPLE
136139
$pullRequest = Get-GitHubPullRequest

tests/Resolve-PSModuleVersion.Helpers.Tests.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,30 @@ Describe 'Non-PR event keeps the current version' {
231231
$result.Prerelease | Should -BeNullOrEmpty
232232
}
233233
}
234+
235+
Describe 'Get-GitHubPullRequest' {
236+
# Covers the non-PR branch: on an event without a pull_request (workflow_dispatch/schedule)
237+
# the function must return $null so the caller keeps the current version, and it must still
238+
# return the head ref + labels on a pull_request event.
239+
AfterEach {
240+
Remove-Item Env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson -ErrorAction SilentlyContinue
241+
}
242+
243+
It 'returns $null when the event has no pull_request (non-PR event)' {
244+
$env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson = '{ "action": "workflow_dispatch" }'
245+
Get-GitHubPullRequest | Should -BeNullOrEmpty
246+
}
247+
248+
It 'returns the head ref and labels for a pull_request event' {
249+
$eventJson = @{
250+
pull_request = @{
251+
head = @{ ref = 'feat/example' }
252+
labels = @(@{ name = 'patch' }, @{ name = 'prerelease' })
253+
}
254+
} | ConvertTo-Json -Depth 5
255+
$env:PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson = $eventJson
256+
$result = Get-GitHubPullRequest
257+
$result.HeadRef | Should -Be 'feat/example'
258+
($result.Labels -join ',') | Should -Be 'patch,prerelease'
259+
}
260+
}

0 commit comments

Comments
 (0)