-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-PSModuleSettings.Helpers.psm1
More file actions
107 lines (92 loc) · 3.26 KB
/
Copy pathGet-PSModuleSettings.Helpers.psm1
File metadata and controls
107 lines (92 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function Resolve-WorkflowEventRouting {
<#
.SYNOPSIS
Resolves release and execution routing from normalized GitHub event state.
#>
[CmdletBinding()]
[OutputType([PSCustomObject])]
param(
[Parameter(Mandatory)]
[string] $EventName,
[Parameter()]
[string] $EventAction,
[Parameter()]
[bool] $PullRequestIsMerged,
[Parameter()]
[bool] $IsTargetDefaultBranch,
[Parameter()]
[bool] $IsPushToDefaultBranch,
[Parameter()]
[bool] $HasPullRequestContext,
[Parameter()]
[bool] $HasImportantChanges,
[Parameter()]
[bool] $HasPrereleaseLabel,
[Parameter()]
[bool] $AllowDirectPushRelease
)
$isPR = $EventName -eq 'pull_request'
$isPush = $EventName -eq 'push'
$isOpenOrUpdatedPR = $isPR -and $EventAction -in @('opened', 'reopened', 'synchronize', 'labeled', 'unlabeled')
$isOpenOrLabeledPR = $isPR -and $EventAction -in @('opened', 'reopened', 'synchronize', 'labeled')
$isClosedPR = $isPR -and $EventAction -eq 'closed'
$isAbandonedPR = $isClosedPR -and -not $PullRequestIsMerged
$isMergedPR = $isClosedPR -and $PullRequestIsMerged
$shouldPrerelease = $isOpenOrLabeledPR -and $HasPrereleaseLabel -and $HasImportantChanges
$releaseType = if (
$IsPushToDefaultBranch -and
$HasImportantChanges -and
($HasPullRequestContext -or $AllowDirectPushRelease)
) {
'Release'
} elseif ($shouldPrerelease) {
'Prerelease'
} else {
'None'
}
[pscustomobject]@{
IsPR = $isPR
IsPush = $isPush
IsOpenOrUpdatedPR = $isOpenOrUpdatedPR
IsOpenOrLabeledPR = $isOpenOrLabeledPR
IsClosedPR = $isClosedPR
IsAbandonedPR = $isAbandonedPR
IsMergedPR = $isMergedPR
IsTargetDefaultBranch = $IsTargetDefaultBranch
IsPushToDefaultBranch = $IsPushToDefaultBranch
ShouldPrerelease = $shouldPrerelease
ReleaseType = $releaseType
ShouldRunBuildTest = (-not $isClosedPR) -and $HasImportantChanges
ShouldCleanupEvent = (
($releaseType -eq 'Release') -or
$isClosedPR -or
($IsPushToDefaultBranch -and $HasPullRequestContext)
)
}
}
function Select-PullRequestForPush {
<#
.SYNOPSIS
Selects the merged default-branch pull request associated with a pushed commit.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameter is used inside a Sort-Object script block.')]
[CmdletBinding()]
[OutputType([PSCustomObject])]
param(
[Parameter()]
[object[]] $PullRequest,
[Parameter(Mandatory)]
[string] $DefaultBranch,
[Parameter(Mandatory)]
[string] $CommitSha
)
$PullRequest |
Where-Object {
$_.Base.Ref -eq $DefaultBranch -and
-not [string]::IsNullOrWhiteSpace($_.'merged_at') -and
$_.'merge_commit_sha' -eq $CommitSha
} |
Sort-Object -Property @{ Expression = { $_.'merged_at' }; Descending = $true } |
Select-Object -First 1
}