functions/AnyInterestingPRs.ps1

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
function AnyInterestingPRs
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [AllowNull()]
        [AllowEmptyCollection()]
        [string[]]
        $Titles,

        [Parameter(Mandatory=$true)]
        [ValidateSet('patch','minor','major')]
        [string]
        $MaxSemVerIncrement,

        [Parameter()]
        [string[]]
        $PackageWildcardExpressions = @()
    )

    $ErrorActionPreference = 'Stop'

    Enum semver_upgrade_type {
        patch = 0
        minor = 1
        major = 2
    }
    $maxSemVerIncrementAsEnum = [semver_upgrade_type]$MaxSemVerIncrement

    $result = $false
    foreach ($prTitle in $Titles) {
        Write-Verbose ('Checking PR: {0}' -f $prTitle)
        
        # parse the PR title
        $packageName,$fromVersion,$toVersion,$folder = ParsePrTitle -Title $prTitle
        Write-Verbose ('Package: {0}' -f $packageName)

        # apply package filter
        $matchFound = IsPackageInteresting -PackageName $packageName -PackageWildcardExpressions $PackageWildcardExpressions
        Write-Verbose ('Match Found?: {0}' -f $matchFound)

        # derive upgrade type
        [semver_upgrade_type]$upgradeType = GetSemVerIncrement -FromVersion $fromVersion -ToVersion $toVersion

        if ($matchFound -and ($upgradeType -le $maxSemVerIncrementAsEnum)) {
            Write-Verbose 'Setting result to true'
            $result = $true
        }
    }

    Write-Verbose ('Result: {0}' -f $result)
    return $result
}