Skip to content

Commit 95b22e8

Browse files
committed
Update the WhatIf/ShouldProcess handling per microsoft#254
1 parent ae6e6ca commit 95b22e8

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
@@ -107,11 +107,8 @@ filter Get-GitHubRelease
107107
Information about published releases are available to everyone. Only users with push
108108
access will receive listings for draft releases.
109109
#>
110-
[CmdletBinding(
111-
SupportsShouldProcess,
112-
DefaultParameterSetName='Elements')]
110+
[CmdletBinding(DefaultParameterSetName='Elements')]
113111
[OutputType({$script:GitHubReleaseTypeName})]
114-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
115112
param(
116113
[Parameter(ParameterSetName='Elements')]
117114
[Parameter(ParameterSetName="Elements-ReleaseId")]
@@ -312,7 +309,6 @@ filter New-GitHubRelease
312309
SupportsShouldProcess,
313310
DefaultParameterSetName='Elements')]
314311
[OutputType({$script:GitHubReleaseTypeName})]
315-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
316312
param(
317313
[Parameter(ParameterSetName='Elements')]
318314
[string] $OwnerName,
@@ -383,6 +379,11 @@ filter New-GitHubRelease
383379
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
384380
}
385381

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

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

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

@@ -666,10 +671,12 @@ filter Remove-GitHubRelease
666671
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
667672
}
668673

669-
if ($PSCmdlet.ShouldProcess($Release, "Deleting release"))
674+
if (-not $PSCmdlet.ShouldProcess($Release, "Remove GitHub Release"))
670675
{
671-
return Invoke-GHRestMethod @params
676+
return
672677
}
678+
679+
return Invoke-GHRestMethod @params
673680
}
674681

675682
filter Get-GitHubReleaseAsset
@@ -748,11 +755,8 @@ filter Get-GitHubReleaseAsset
748755
Downloads the asset 1234567890 to 'c:\users\PowerShellForGitHub\downloads\asset.zip' and
749756
overwrites the file that may already be there.
750757
#>
751-
[CmdletBinding(
752-
SupportsShouldProcess,
753-
DefaultParameterSetName='Elements-List')]
758+
[CmdletBinding(DefaultParameterSetName='Elements-List')]
754759
[OutputType({$script:GitHubReleaseAssetTypeName})]
755-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
756760
[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.")]
757761
param(
758762
[Parameter(ParameterSetName='Elements-List')]
@@ -971,7 +975,6 @@ filter New-GitHubReleaseAsset
971975
SupportsShouldProcess,
972976
DefaultParameterSetName='Elements')]
973977
[OutputType({$script:GitHubReleaseAssetTypeName})]
974-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
975978
[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.")]
976979
param(
977980
[Parameter(ParameterSetName='Elements')]
@@ -1065,6 +1068,11 @@ filter New-GitHubReleaseAsset
10651068
$labelEncoded = [Uri]::EscapeDataString($Label)
10661069
if (-not [String]::IsNullOrWhiteSpace($Label)) { $queryParams += "label=$labelEncoded" }
10671070

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

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

1332-
if ($PSCmdlet.ShouldProcess($Asset, "Deleting asset"))
1344+
if (-not $PSCmdlet.ShouldProcess($Asset, "Delete GitHub Release Asset"))
13331345
{
1334-
return Invoke-GHRestMethod @params
1346+
return
13351347
}
1348+
1349+
return Invoke-GHRestMethod @params
13361350
}
13371351

13381352
filter Add-GitHubReleaseAdditionalProperties

0 commit comments

Comments
 (0)