diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 2e15d2c7..f137b151 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -107,11 +107,8 @@ filter Get-GitHubRelease Information about published releases are available to everyone. Only users with push access will receive listings for draft releases. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName='Elements')] [OutputType({$script:GitHubReleaseTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [Parameter(ParameterSetName="Elements-ReleaseId")] @@ -312,7 +309,6 @@ filter New-GitHubRelease SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubReleaseTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -383,6 +379,11 @@ filter New-GitHubRelease 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + if (-not $PSCmdlet.ShouldProcess($TagName, "Create release for $RepositoryName at tag")) + { + return + } + return (Invoke-GHRestMethod @params | Add-GitHubReleaseAdditionalProperties) } @@ -472,7 +473,6 @@ filter Set-GitHubRelease SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubReleaseTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -547,6 +547,11 @@ filter Set-GitHubRelease 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + if (-not $PSCmdlet.ShouldProcess($Release, "Update GitHub Release")) + { + return + } + return (Invoke-GHRestMethod @params | Add-GitHubReleaseAdditionalProperties) } @@ -666,10 +671,12 @@ filter Remove-GitHubRelease 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - if ($PSCmdlet.ShouldProcess($Release, "Deleting release")) + if (-not $PSCmdlet.ShouldProcess($Release, "Remove GitHub Release")) { - return Invoke-GHRestMethod @params + return } + + return Invoke-GHRestMethod @params } filter Get-GitHubReleaseAsset @@ -748,11 +755,8 @@ filter Get-GitHubReleaseAsset Downloads the asset 1234567890 to 'c:\users\PowerShellForGitHub\downloads\asset.zip' and overwrites the file that may already be there. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements-List')] + [CmdletBinding(DefaultParameterSetName='Elements-List')] [OutputType({$script:GitHubReleaseAssetTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements-List')] @@ -971,7 +975,6 @@ filter New-GitHubReleaseAsset SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubReleaseAssetTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -1065,6 +1068,11 @@ filter New-GitHubReleaseAsset $labelEncoded = [Uri]::EscapeDataString($Label) if (-not [String]::IsNullOrWhiteSpace($Label)) { $queryParams += "label=$labelEncoded" } + if (-not $PSCmdlet.ShouldProcess($Path, "Create new GitHub Release Asset")) + { + return + } + $params = @{ 'UriFragment' = $UploadUrl + '?' + ($queryParams -join '&') 'Method' = 'Post' @@ -1154,7 +1162,6 @@ filter Set-GitHubReleaseAsset SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubReleaseAssetTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -1202,6 +1209,11 @@ filter Set-GitHubReleaseAsset if (-not [String]::IsNullOrWhiteSpace($Name)) { $hashBody['name'] = $Name } if (-not [String]::IsNullOrWhiteSpace($Label)) { $hashBody['label'] = $Label } + if (-not $PSCmdlet.ShouldProcess($Asset, "Update GitHub Release Asset")) + { + return + } + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/assets/$Asset" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1329,10 +1341,12 @@ filter Remove-GitHubReleaseAsset 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - if ($PSCmdlet.ShouldProcess($Asset, "Deleting asset")) + if (-not $PSCmdlet.ShouldProcess($Asset, "Delete GitHub Release Asset")) { - return Invoke-GHRestMethod @params + return } + + return Invoke-GHRestMethod @params } filter Add-GitHubReleaseAdditionalProperties