Functions/Public/Get-GitHubRelease.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function Get-GitHubRelease {
<#
    .SYNOPSIS
    Get a list of releases for a Repository
 
    .DESCRIPTION
    Get a list of releases for a Repository
 
    .PARAMETER Repository
    The name of the repository
 
    .PARAMETER Id
    The id of the release
 
    .PARAMETER Tag
    The tag associated with the release
 
    .PARAMETER Latest
    Retrieve the latest release
 
    .PARAMETER Page
    The page number to return
 
    .PARAMETER PerPage
    The number of entries per page
 
    .INPUTS
    System.String
    System.Int
    Switch
 
    .OUTPUTS
    System.Management.Automation.PSObject
 
    .EXAMPLE
    Get-GitHubRelease -Repository MyRepository
 
    .EXAMPLE
    Get-GitHubRelease -Repository MyRepository -Id xxxxx
 
    .EXAMPLE
    Get-GitHubRelease -Repository MyRepository -Tag v.1.0
 
    .EXAMPLE
    Get-GitHubRelease -Repository MyRepository -Latest
 
#>

[CmdletBinding(DefaultParameterSetName="Standard")][OutputType('System.Management.Automation.PSObject')]

    Param (

        [Parameter(Mandatory=$true, Position=0)]
        [ValidateNotNullOrEmpty()]
        [String]$Repository,

        [Parameter(Mandatory=$true, Position=1, ParameterSetName="ById")]
        [ValidateNotNullOrEmpty()]
        [String]$Id,

        [Parameter(Mandatory=$true, Position=2, ParameterSetName="ByTagName")]
        [ValidateNotNullOrEmpty()]
        [String]$Tag,

        [Parameter(Mandatory=$true, Position=3, ParameterSetName="Latest")]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.SwitchParameter]$Latest,

        [Parameter(Mandatory=$false, Position=4, ParameterSetName="Standard")]
        [ValidateNotNullOrEmpty()]
        [Int]$Page = 1,

        [Parameter(Mandatory=$false, Position=5, ParameterSetName="Standard")]
        [ValidateNotNullOrEmpty()]
        [Int]$PerPage = 30

    )

    try {

        # --- Grab the sessionstate variable & test throw if it is null
        $SessionInfo = Get-GitHubSessionInformation -Verbose:$VerbosePreference

        switch ($PSCmdlet.ParameterSetName){

            "Standard" {

                Write-Verbose -Message "Retrieving all releases for Repository $($Repository)"
                $URI = "/repos/$($SessionInfo.Username)/$($Repository)/releases?page=$($page)&per_page=$($PerPage)"
                break
            }

            "ById" {

                Write-Verbose -Message "Retrieving release $($Id) for $($Repository)"
                $URI = "/repos/$($SessionInfo.Username)/$($Repository)/releases/$($Id)"
                break
            }

            "ByTagName" {

                Write-Verbose -Message "Retrieving release with tag $($Tag) for Repository $($Repository)"
                $URI = "/repos/$($SessionInfo.Username)/$($Repository)/releases/tags/$($Tag)"
                break
            }

            "Latest" {

                Write-Verbose -Message "Retrieving latest release for Repository $($Repository)"
                $URI = "/repos/$($SessionInfo.Username)/$($Repository)/releases/latest"
                break
            }

        }

        Invoke-GitHubRestMethod -Method GET -URI $URI -Verbose:$VerbosePreference

    }
    catch [Exception]{

        throw $_.Exception

    }

}