Skip to content

Commit a6a27aa

Browse files
BREAKING CHANGE: Add confirmation prompts and examples for Remove- functions (#174)
Updates all Remove-* functions to set `ConfirmImpact='High'`, wraps the execution in `$PSCmdlet.ShouldProcess()`, and adds examples which show how to call the functions with `-Confirm:$false` to avoid the confirmation prompt. ## Breaking Change This will be considered a breaking change for anyone using this module in an automated, scripted basis and calling any Remove-* methods. They will need to add `-Confirm:$false` to those API calls, similar to what was done for the unit tests. Fixes #171
1 parent 21e6139 commit a6a27aa

19 files changed

+178
-129
lines changed

GitHubAssignees.ps1

+22-14
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,16 @@ function Remove-GithubAssignee
328328
Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees
329329
330330
Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project.
331+
332+
.EXAMPLE
333+
Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Confirm:$false
334+
335+
Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
331336
#>
332337
[CmdletBinding(
333338
SupportsShouldProcess,
334-
DefaultParameterSetName='Elements')]
335-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
339+
DefaultParameterSetName='Elements',
340+
ConfirmImpact="High")]
336341
[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.")]
337342
param(
338343
[Parameter(ParameterSetName='Elements')]
@@ -374,17 +379,20 @@ function Remove-GithubAssignee
374379
'assignees' = $Assignee
375380
}
376381

377-
$params = @{
378-
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees"
379-
'Body' = (ConvertTo-Json -InputObject $hashBody)
380-
'Method' = 'Delete'
381-
'Description' = "Removing assignees from issue $Issue for $RepositoryName"
382-
'AccessToken' = $AccessToken
383-
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
384-
'TelemetryEventName' = $MyInvocation.MyCommand.Name
385-
'TelemetryProperties' = $telemetryProperties
386-
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
382+
if ($PSCmdlet.ShouldProcess($Assignee -join ', ', "Remove assignee(s)"))
383+
{
384+
$params = @{
385+
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees"
386+
'Body' = (ConvertTo-Json -InputObject $hashBody)
387+
'Method' = 'Delete'
388+
'Description' = "Removing assignees from issue $Issue for $RepositoryName"
389+
'AccessToken' = $AccessToken
390+
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
391+
'TelemetryEventName' = $MyInvocation.MyCommand.Name
392+
'TelemetryProperties' = $telemetryProperties
393+
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
394+
}
395+
396+
return Invoke-GHRestMethod @params
387397
}
388-
389-
return Invoke-GHRestMethod @params
390398
}

GitHubComments.ps1

+20-12
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,17 @@ function Remove-GitHubComment
452452
Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1
453453
454454
Deletes a Github comment from the Microsoft\PowerShellForGitHub project.
455+
456+
.EXAMPLE
457+
Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Confirm:$false
458+
459+
Deletes a Github comment from the Microsoft\PowerShellForGitHub project without prompting confirmation.
455460
#>
456461
[CmdletBinding(
457462
SupportsShouldProcess,
458-
DefaultParameterSetName='Elements')]
463+
DefaultParameterSetName='Elements',
464+
ConfirmImpact="High")]
459465
[Alias('Delete-GitHubComment')]
460-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
461466
[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.")]
462467
param(
463468
[Parameter(ParameterSetName='Elements')]
@@ -491,16 +496,19 @@ function Remove-GitHubComment
491496
'CommentID' = (Get-PiiSafeString -PlainText $CommentID)
492497
}
493498

494-
$params = @{
495-
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$CommentID"
496-
'Method' = 'Delete'
497-
'Description' = "Removing comment $CommentID for $RepositoryName"
498-
'AccessToken' = $AccessToken
499-
'TelemetryEventName' = $MyInvocation.MyCommand.Name
500-
'TelemetryProperties' = $telemetryProperties
501-
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
502-
}
499+
if ($PSCmdlet.ShouldProcess($CommentID, "Remove comment"))
500+
{
501+
$params = @{
502+
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$CommentID"
503+
'Method' = 'Delete'
504+
'Description' = "Removing comment $CommentID for $RepositoryName"
505+
'AccessToken' = $AccessToken
506+
'TelemetryEventName' = $MyInvocation.MyCommand.Name
507+
'TelemetryProperties' = $telemetryProperties
508+
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
509+
}
503510

504-
return Invoke-GHRestMethod @params
511+
return Invoke-GHRestMethod @params
512+
}
505513
}
506514

GitHubLabels.ps1

+43-27
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,16 @@ function Remove-GitHubLabel
316316
Remove-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel
317317
318318
Removes the label called "TestLabel" from the PowerShellForGitHub project.
319+
320+
.EXAMPLE
321+
Remove-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Confirm:$false
322+
323+
Removes the label called "TestLabel" from the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
319324
#>
320325
[CmdletBinding(
321326
SupportsShouldProcess,
322-
DefaultParameterSetName='Elements')]
323-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
327+
DefaultParameterSetName='Elements',
328+
ConfirmImpact="High")]
324329
[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.")]
325330
[Alias('Delete-GitHubLabel')]
326331
param(
@@ -356,18 +361,21 @@ function Remove-GitHubLabel
356361
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
357362
}
358363

359-
$params = @{
360-
'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Name"
361-
'Method' = 'Delete'
362-
'Description' = "Deleting label $Name from $RepositoryName"
363-
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
364-
'AccessToken' = $AccessToken
365-
'TelemetryEventName' = $MyInvocation.MyCommand.Name
366-
'TelemetryProperties' = $telemetryProperties
367-
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
368-
}
364+
if ($PSCmdlet.ShouldProcess($Name, "Remove label"))
365+
{
366+
$params = @{
367+
'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Name"
368+
'Method' = 'Delete'
369+
'Description' = "Deleting label $Name from $RepositoryName"
370+
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
371+
'AccessToken' = $AccessToken
372+
'TelemetryEventName' = $MyInvocation.MyCommand.Name
373+
'TelemetryProperties' = $telemetryProperties
374+
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
375+
}
369376

370-
return Invoke-GHRestMethod @params
377+
return Invoke-GHRestMethod @params
378+
}
371379
}
372380

373381
function Update-GitHubLabel
@@ -614,7 +622,7 @@ function Set-GitHubLabel
614622
if ($labelName -notin $labelNames)
615623
{
616624
# Remove label if it exists but is not in desired label list
617-
$null = Remove-GitHubLabel -Name $labelName @commonParams
625+
$null = Remove-GitHubLabel -Name $labelName @commonParams -Confirm:$false
618626
}
619627
}
620628
}
@@ -865,11 +873,16 @@ function Remove-GitHubIssueLabel
865873
Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Issue 1
866874
867875
Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project.
876+
877+
.EXAMPLE
878+
Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Issue 1 -Confirm:$false
879+
880+
Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
868881
#>
869882
[CmdletBinding(
870883
SupportsShouldProcess,
871-
DefaultParameterSetName='Elements')]
872-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
884+
DefaultParameterSetName='Elements',
885+
ConfirmImpact="High")]
873886
[Alias('Delete-GitHubLabel')]
874887
param(
875888
[Parameter(Mandatory, ParameterSetName='Elements')]
@@ -915,18 +928,21 @@ function Remove-GitHubIssueLabel
915928
$description = "Deleting all labels from issue $Issue in $RepositoryName"
916929
}
917930

918-
$params = @{
919-
'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Name"
920-
'Method' = 'Delete'
921-
'Description' = $description
922-
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
923-
'AccessToken' = $AccessToken
924-
'TelemetryEventName' = $MyInvocation.MyCommand.Name
925-
'TelemetryProperties' = $telemetryProperties
926-
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
927-
}
931+
if ($PSCmdlet.ShouldProcess($Name, "Remove label"))
932+
{
933+
$params = @{
934+
'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Name"
935+
'Method' = 'Delete'
936+
'Description' = $description
937+
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
938+
'AccessToken' = $AccessToken
939+
'TelemetryEventName' = $MyInvocation.MyCommand.Name
940+
'TelemetryProperties' = $telemetryProperties
941+
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
942+
}
928943

929-
return Invoke-GHRestMethod @params
944+
return Invoke-GHRestMethod @params
945+
}
930946
}
931947

932948
# A set of labels that a project might want to initially populate their repository with

GitHubMilestones.ps1

+20-12
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,17 @@ function Remove-GitHubMilestone
500500
Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1
501501
502502
Deletes a Github milestone from the Microsoft\PowerShellForGitHub project.
503+
504+
.EXAMPLE
505+
Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Confirm:$false
506+
507+
Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
503508
#>
504509
[CmdletBinding(
505510
SupportsShouldProcess,
506-
DefaultParameterSetName='Elements')]
511+
DefaultParameterSetName='Elements',
512+
ConfirmImpact="High")]
507513
[Alias('Delete-GitHubMilestone')]
508-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
509514
[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.")]
510515
param(
511516
[Parameter(Mandatory, ParameterSetName='Elements')]
@@ -538,15 +543,18 @@ function Remove-GitHubMilestone
538543
'Milestone' = (Get-PiiSafeString -PlainText $Milestone)
539544
}
540545

541-
$params = @{
542-
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone"
543-
'Method' = 'Delete'
544-
'Description' = "Removing milestone $Milestone for $RepositoryName"
545-
'AccessToken' = $AccessToken
546-
'TelemetryEventName' = $MyInvocation.MyCommand.Name
547-
'TelemetryProperties' = $telemetryProperties
548-
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
549-
}
546+
if ($PSCmdlet.ShouldProcess($Milestone, "Remove milestone"))
547+
{
548+
$params = @{
549+
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone"
550+
'Method' = 'Delete'
551+
'Description' = "Removing milestone $Milestone for $RepositoryName"
552+
'AccessToken' = $AccessToken
553+
'TelemetryEventName' = $MyInvocation.MyCommand.Name
554+
'TelemetryProperties' = $telemetryProperties
555+
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
556+
}
550557

551-
return Invoke-GHRestMethod @params
558+
return Invoke-GHRestMethod @params
559+
}
552560
}

GitHubProjectCards.ps1

-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ function Remove-GitHubProjectCard
370370
SupportsShouldProcess,
371371
ConfirmImpact = 'High')]
372372
[Alias('Delete-GitHubProjectCard')]
373-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
374373
[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.")]
375374
param(
376375
[Parameter(Mandatory)]

GitHubProjectColumns.ps1

-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ function Remove-GitHubProjectColumn
266266
SupportsShouldProcess,
267267
ConfirmImpact = 'High')]
268268
[Alias('Delete-GitHubProjectColumn')]
269-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
270269
[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.")]
271270
param(
272271
[Parameter(Mandatory)]

GitHubProjects.ps1

+5-1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@ function Remove-GitHubProject
465465
466466
Remove project with ID '4387531'.
467467
468+
.EXAMPLE
469+
Remove-GitHubProject -Project 4387531 -Confirm:$false
470+
471+
Remove project with ID '4387531' without prompting for confirmation.
472+
468473
.EXAMPLE
469474
$project = Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject'
470475
Remove-GitHubProject -Project $project.id
@@ -476,7 +481,6 @@ function Remove-GitHubProject
476481
SupportsShouldProcess,
477482
ConfirmImpact = 'High')]
478483
[Alias('Delete-GitHubProject')]
479-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
480484
[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.")]
481485
param(
482486
[Parameter(Mandatory)]

GitHubRepositories.ps1

+19-12
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,17 @@ function Remove-GitHubRepository
217217
218218
.EXAMPLE
219219
Remove-GitHubRepository -Uri https://github.com/You/YourRepoToDelete
220+
221+
.EXAMPLE
222+
Remove-GitHubRepository -Uri https://github.com/You/YourRepoToDelete -Confirm:$false
223+
224+
Remove repository with the given URI, without prompting for confirmation.
220225
#>
221226
[CmdletBinding(
222227
SupportsShouldProcess,
223-
DefaultParameterSetName='Elements')]
228+
DefaultParameterSetName='Elements',
229+
ConfirmImpact="High")]
224230
[Alias('Delete-GitHubRepository')]
225-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
226231
param(
227232
[Parameter(ParameterSetName='Elements')]
228233
[string] $OwnerName,
@@ -250,18 +255,20 @@ function Remove-GitHubRepository
250255
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
251256
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
252257
}
258+
if ($PSCmdlet.ShouldProcess($RepositoryName, "Remove repository"))
259+
{
260+
$params = @{
261+
'UriFragment' = "repos/$OwnerName/$RepositoryName"
262+
'Method' = 'Delete'
263+
'Description' = "Deleting $RepositoryName"
264+
'AccessToken' = $AccessToken
265+
'TelemetryEventName' = $MyInvocation.MyCommand.Name
266+
'TelemetryProperties' = $telemetryProperties
267+
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus)
268+
}
253269

254-
$params = @{
255-
'UriFragment' = "repos/$OwnerName/$RepositoryName"
256-
'Method' = 'Delete'
257-
'Description' = "Deleting $RepositoryName"
258-
'AccessToken' = $AccessToken
259-
'TelemetryEventName' = $MyInvocation.MyCommand.Name
260-
'TelemetryProperties' = $telemetryProperties
261-
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus)
270+
return Invoke-GHRestMethod @params
262271
}
263-
264-
return Invoke-GHRestMethod @params
265272
}
266273

267274
function Get-GitHubRepository

0 commit comments

Comments
 (0)