|
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +function Get-GitHubRelease |
| 5 | +{ |
| 6 | +<# |
| 7 | + .SYNOPSIS |
| 8 | + Retrieves information about a release or list of releases on GitHub. |
| 9 | +
|
| 10 | + .DESCRIPTION |
| 11 | + Retrieves information about a release or list of releases on GitHub. |
| 12 | +
|
| 13 | + The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub |
| 14 | +
|
| 15 | + .PARAMETER OwnerName |
| 16 | + Owner of the repository. |
| 17 | + If not supplied here, the DefaultOwnerName configuration property value will be used. |
| 18 | +
|
| 19 | + .PARAMETER RepositoryName |
| 20 | + Name of the repository. |
| 21 | + If not supplied here, the DefaultRepositoryName configuration property value will be used. |
| 22 | +
|
| 23 | + .PARAMETER Uri |
| 24 | + Uri for the repository. |
| 25 | + The OwnerName and RepositoryName will be extracted from here instead of needing to provide |
| 26 | + them individually. |
| 27 | +
|
| 28 | + .PARAMETER ReleaseId |
| 29 | + Specific releaseId of a release. |
| 30 | + This is an optional parameter which can limit the results to a single release. |
| 31 | +
|
| 32 | + .PARAMETER Latest |
| 33 | + Retrieve only the latest release. |
| 34 | + This is an optional parameter which can limit the results to a single release. |
| 35 | +
|
| 36 | + .PARAMETER Tag |
| 37 | + Retrieves a list of releases with the associated tag. |
| 38 | + This is an optional parameter which can filter the list of releases. |
| 39 | +
|
| 40 | + .PARAMETER AccessToken |
| 41 | + If provided, this will be used as the AccessToken for authentication with the |
| 42 | + REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. |
| 43 | +
|
| 44 | + .PARAMETER NoStatus |
| 45 | + If this switch is specified, long-running commands will run on the main thread |
| 46 | + with no commandline status update. When not specified, those commands run in |
| 47 | + the background, enabling the command prompt to provide status information. |
| 48 | + If not supplied here, the DefaultNoStatus configuration property value will be used. |
| 49 | +
|
| 50 | + .EXAMPLE |
| 51 | + Get-GitHubRelease |
| 52 | +
|
| 53 | + Gets all releases for the default configured owner/repository. |
| 54 | +
|
| 55 | + .EXAMPLE |
| 56 | + Get-GitHubRelease -ReleaseId 12345 |
| 57 | +
|
| 58 | + Get a specific release for the default configured owner/repository |
| 59 | +
|
| 60 | + .EXAMPLE |
| 61 | + Get-GitHubRelease -OwnerName dotnet -RepositoryName core |
| 62 | +
|
| 63 | + Gets all releases from the dotnet\core repository. |
| 64 | +
|
| 65 | + .EXAMPLE |
| 66 | + Get-GitHubRelease -Uri https://github.com/microsoft/PowerShellForGitHub |
| 67 | +
|
| 68 | + Gets all releases from the microsoft/PowerShellForGitHub repository. |
| 69 | +
|
| 70 | + .EXAMPLE |
| 71 | + Get-GitHubRelease -OwnerName dotnet -RepositoryName core -Latest |
| 72 | +
|
| 73 | + Gets the latest release from the dotnet\core repository. |
| 74 | +
|
| 75 | + .EXAMPLE |
| 76 | + Get-GitHubRelease -Uri https://github.com/microsoft/PowerShellForGitHub -Tag 0.8.0 |
| 77 | +
|
| 78 | + Gets the release tagged with 0.8.0 from the microsoft/PowerShellForGitHub repository. |
| 79 | +
|
| 80 | + .NOTES |
| 81 | + Information about published releases are available to everyone. Only users with push |
| 82 | + access will receive listings for draft releases. |
| 83 | +#> |
| 84 | + [CmdletBinding( |
| 85 | + SupportsShouldProcess, |
| 86 | + DefaultParametersetName='Elements')] |
| 87 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] |
| 88 | + param( |
| 89 | + [Parameter( |
| 90 | + ParameterSetName='Elements')] |
| 91 | + [Parameter( |
| 92 | + ParameterSetName="Elements-ReleaseId")] |
| 93 | + [Parameter( |
| 94 | + ParameterSetName="Elements-Latest")] |
| 95 | + [Parameter( |
| 96 | + ParameterSetName="Elements-Tag")] |
| 97 | + [string] $OwnerName, |
| 98 | + |
| 99 | + [Parameter( |
| 100 | + ParameterSetName='Elements')] |
| 101 | + [Parameter( |
| 102 | + ParameterSetName="Elements-ReleaseId")] |
| 103 | + [Parameter( |
| 104 | + ParameterSetName="Elements-Latest")] |
| 105 | + [Parameter( |
| 106 | + ParameterSetName="Elements-Tag")] |
| 107 | + [string] $RepositoryName, |
| 108 | + |
| 109 | + [Parameter( |
| 110 | + Mandatory, |
| 111 | + ParameterSetName='Uri')] |
| 112 | + [Parameter( |
| 113 | + Mandatory, |
| 114 | + ParameterSetName="Uri-ReleaseId")] |
| 115 | + [Parameter( |
| 116 | + Mandatory, |
| 117 | + ParameterSetName="Uri-Latest")] |
| 118 | + [Parameter( |
| 119 | + Mandatory, |
| 120 | + ParameterSetName="Uri-Tag")] |
| 121 | + [string] $Uri, |
| 122 | + |
| 123 | + [Parameter( |
| 124 | + Mandatory, |
| 125 | + ParameterSetName="Elements-ReleaseId")] |
| 126 | + [Parameter( |
| 127 | + Mandatory, |
| 128 | + ParameterSetName="Uri-ReleaseId")] |
| 129 | + [string] $ReleaseId, |
| 130 | + |
| 131 | + [Parameter( |
| 132 | + Mandatory, |
| 133 | + ParameterSetName="Elements-Latest")] |
| 134 | + [Parameter( |
| 135 | + Mandatory, |
| 136 | + ParameterSetName="Uri-Latest")] |
| 137 | + [switch] $Latest, |
| 138 | + |
| 139 | + [Parameter( |
| 140 | + Mandatory, |
| 141 | + ParameterSetName="Elements-Tag")] |
| 142 | + [Parameter( |
| 143 | + Mandatory, |
| 144 | + ParameterSetName="Uri-Tag")] |
| 145 | + [string] $Tag, |
| 146 | + |
| 147 | + [string] $AccessToken, |
| 148 | + |
| 149 | + [switch] $NoStatus |
| 150 | + ) |
| 151 | + |
| 152 | + Write-InvocationLog -Invocation $MyInvocation |
| 153 | + |
| 154 | + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters -DisableValidation |
| 155 | + $OwnerName = $elements.ownerName |
| 156 | + $RepositoryName = $elements.repositoryName |
| 157 | + |
| 158 | + $telemetryProperties = @{} |
| 159 | + |
| 160 | + $telemetryProperties['OwnerName'] = Get-PiiSafeString -PlainText $OwnerName |
| 161 | + $telemetryProperties['RepositoryName'] = Get-PiiSafeString -PlainText $RepositoryName |
| 162 | + |
| 163 | + $uriFragment = "repos/$OwnerName/$RepositoryName/releases" |
| 164 | + $description = "Getting releases for $OwnerName/$RepositoryName" |
| 165 | + |
| 166 | + if(-not [String]::IsNullOrEmpty($ReleaseId)) |
| 167 | + { |
| 168 | + $telemetryProperties['ProvidedReleaseId'] = $true |
| 169 | + |
| 170 | + $uriFragment += "/$ReleaseId" |
| 171 | + $description = "Getting release information for $ReleaseId from $OwnerName/$RepositoryName" |
| 172 | + } |
| 173 | + |
| 174 | + if($Latest) |
| 175 | + { |
| 176 | + $telemetryProperties['GetLatest'] = $true |
| 177 | + |
| 178 | + $uriFragment += "/latest" |
| 179 | + $description = "Getting latest release from $OwnerName/$RepositoryName" |
| 180 | + } |
| 181 | + |
| 182 | + if(-not [String]::IsNullOrEmpty($Tag)) |
| 183 | + { |
| 184 | + $telemetryProperties['ProvidedTag'] = $true |
| 185 | + |
| 186 | + $uriFragment += "/tags/$Tag" |
| 187 | + $description = "Getting releases tagged with $Tag from $OwnerName/$RepositoryName" |
| 188 | + } |
| 189 | + |
| 190 | + $params = @{ |
| 191 | + 'UriFragment' = $uriFragment |
| 192 | + 'Description' = $description |
| 193 | + 'AccessToken' = $AccessToken |
| 194 | + 'TelemetryEventName' = $MyInvocation.MyCommand.Name |
| 195 | + 'TelemetryProperties' = $telemetryProperties |
| 196 | + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) |
| 197 | + } |
| 198 | + |
| 199 | + return Invoke-GHRestMethodMultipleResult @params |
| 200 | +} |
0 commit comments