Skip to content

Commit 9bcaeb3

Browse files
committed
Update the WhatIf/ShouldProcess handling per microsoft#254
1 parent 228231b commit 9bcaeb3

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

GitHubReleases.ps1

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,8 @@ filter Get-GitHubRelease
108108
Information about published releases are available to everyone. Only users with push
109109
access will receive listings for draft releases.
110110
#>
111-
[CmdletBinding(
112-
SupportsShouldProcess,
113-
DefaultParameterSetName='Elements')]
111+
[CmdletBinding(DefaultParameterSetName='Elements')]
114112
[OutputType({$script:GitHubReleaseTypeName})]
115-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
116113
param(
117114
[Parameter(ParameterSetName='Elements')]
118115
[Parameter(ParameterSetName="Elements-ReleaseId")]
@@ -313,7 +310,6 @@ filter New-GitHubRelease
313310
SupportsShouldProcess,
314311
DefaultParameterSetName='Elements')]
315312
[OutputType({$script:GitHubReleaseTypeName})]
316-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
317313
param(
318314
[Parameter(ParameterSetName='Elements')]
319315
[string] $OwnerName,
@@ -384,6 +380,11 @@ filter New-GitHubRelease
384380
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
385381
}
386382

383+
if (-not $PSCmdlet.ShouldProcess($TagName, "Create release for $RepositoryName at tag"))
384+
{
385+
return
386+
}
387+
387388
return (Invoke-GHRestMethod @params | Add-GitHubReleaseAdditionalProperties)
388389
}
389390

@@ -473,7 +474,6 @@ filter Set-GitHubRelease
473474
SupportsShouldProcess,
474475
DefaultParameterSetName='Elements')]
475476
[OutputType({$script:GitHubReleaseTypeName})]
476-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
477477
param(
478478
[Parameter(ParameterSetName='Elements')]
479479
[string] $OwnerName,
@@ -548,6 +548,11 @@ filter Set-GitHubRelease
548548
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
549549
}
550550

551+
if (-not $PSCmdlet.ShouldProcess($Release, "Update GitHub Release"))
552+
{
553+
return
554+
}
555+
551556
return (Invoke-GHRestMethod @params | Add-GitHubReleaseAdditionalProperties)
552557
}
553558

@@ -667,10 +672,12 @@ filter Remove-GitHubRelease
667672
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
668673
}
669674

670-
if ($PSCmdlet.ShouldProcess($Release, "Deleting release"))
675+
if (-not $PSCmdlet.ShouldProcess($Release, "Remove GitHub Release"))
671676
{
672-
return Invoke-GHRestMethod @params
677+
return
673678
}
679+
680+
return Invoke-GHRestMethod @params
674681
}
675682

676683
filter Get-GitHubReleaseAsset
@@ -749,11 +756,8 @@ filter Get-GitHubReleaseAsset
749756
Downloads the asset 1234567890 to 'c:\users\PowerShellForGitHub\downloads\asset.zip' and
750757
overwrites the file that may already be there.
751758
#>
752-
[CmdletBinding(
753-
SupportsShouldProcess,
754-
DefaultParameterSetName='Elements-List')]
759+
[CmdletBinding(DefaultParameterSetName='Elements-List')]
755760
[OutputType({$script:GitHubReleaseAssetTypeName})]
756-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
757761
[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.")]
758762
param(
759763
[Parameter(ParameterSetName='Elements-List')]
@@ -972,7 +976,6 @@ filter New-GitHubReleaseAsset
972976
SupportsShouldProcess,
973977
DefaultParameterSetName='Elements')]
974978
[OutputType({$script:GitHubReleaseAssetTypeName})]
975-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
976979
[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.")]
977980
param(
978981
[Parameter(ParameterSetName='Elements')]
@@ -1066,6 +1069,11 @@ filter New-GitHubReleaseAsset
10661069
$labelEncoded = [Uri]::EscapeDataString($Label)
10671070
if (-not [String]::IsNullOrWhiteSpace($Label)) { $queryParams += "label=$labelEncoded" }
10681071

1072+
if (-not $PSCmdlet.ShouldProcess($Path, "Create new GitHub Release Asset"))
1073+
{
1074+
return
1075+
}
1076+
10691077
$params = @{
10701078
'UriFragment' = $UploadUrl + '?' + ($queryParams -join '&')
10711079
'Method' = 'Post'
@@ -1155,7 +1163,6 @@ filter Set-GitHubReleaseAsset
11551163
SupportsShouldProcess,
11561164
DefaultParameterSetName='Elements')]
11571165
[OutputType({$script:GitHubReleaseAssetTypeName})]
1158-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
11591166
[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.")]
11601167
param(
11611168
[Parameter(ParameterSetName='Elements')]
@@ -1203,6 +1210,11 @@ filter Set-GitHubReleaseAsset
12031210
if (-not [String]::IsNullOrWhiteSpace($Name)) { $hashBody['name'] = $Name }
12041211
if (-not [String]::IsNullOrWhiteSpace($Label)) { $hashBody['label'] = $Label }
12051212

1213+
if (-not $PSCmdlet.ShouldProcess($Asset, "Update GitHub Release Asset"))
1214+
{
1215+
return
1216+
}
1217+
12061218
$params = @{
12071219
'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/assets/$Asset"
12081220
'Body' = (ConvertTo-Json -InputObject $hashBody)
@@ -1330,10 +1342,12 @@ filter Remove-GitHubReleaseAsset
13301342
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
13311343
}
13321344

1333-
if ($PSCmdlet.ShouldProcess($Asset, "Deleting asset"))
1345+
if (-not $PSCmdlet.ShouldProcess($Asset, "Delete GitHub Release Asset"))
13341346
{
1335-
return Invoke-GHRestMethod @params
1347+
return
13361348
}
1349+
1350+
return Invoke-GHRestMethod @params
13371351
}
13381352

13391353
filter Add-GitHubReleaseAdditionalProperties

0 commit comments

Comments
 (0)