Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add confirmation prompts and examples for Remove- functions #174

35 changes: 22 additions & 13 deletions GitHubAssignees.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,16 @@ function Remove-GithubAssignee
Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees

giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project.

.EXAMPLE
Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee $assignees -Confirm:$false

Lists the available assignees for issues from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
DefaultParameterSetName='Elements',
ConfirmImpact="High")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
param(
[Parameter(ParameterSetName='Elements')]
Expand Down Expand Up @@ -370,17 +376,20 @@ function Remove-GithubAssignee
'assignees' = $Assignee
}

$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees"
'Body' = (ConvertTo-Json -InputObject $hashBody)
'Method' = 'Delete'
'Description' = "Removing assignees from issue $Issue for $RepositoryName"
'AccessToken' = $AccessToken
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
if ($PSCmdlet.ShouldProcess($Assignee -join ', ', "Remove assignee(s)"))
{
$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees"
'Body' = (ConvertTo-Json -InputObject $hashBody)
'Method' = 'Delete'
'Description' = "Removing assignees from issue $Issue for $RepositoryName"
'AccessToken' = $AccessToken
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

return Invoke-GHRestMethod @params
}

return Invoke-GHRestMethod @params
}
31 changes: 20 additions & 11 deletions GitHubComments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,16 @@ function Remove-GitHubComment
Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1

Deletes a Github comment from the Microsoft\PowerShellForGitHub project.

.EXAMPLE
Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Confirm:$false

Deletes a Github comment from the Microsoft\PowerShellForGitHub project without prompting confirmation.
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
DefaultParameterSetName='Elements',
ConfirmImpact="High")]
[Alias('Delete-GitHubComment')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
param(
Expand Down Expand Up @@ -488,16 +494,19 @@ function Remove-GitHubComment
'CommentID' = (Get-PiiSafeString -PlainText $CommentID)
}

$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$CommentID"
'Method' = 'Delete'
'Description' = "Removing comment $CommentID for $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}
if ($PSCmdlet.ShouldProcess($CommentID, "Remove comment"))
{
$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$CommentID"
'Method' = 'Delete'
'Description' = "Removing comment $CommentID for $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

return Invoke-GHRestMethod @params
return Invoke-GHRestMethod @params
}
}

68 changes: 43 additions & 25 deletions GitHubLabels.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,16 @@ function Remove-GitHubLabel
Remove-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel

Removes the label called "TestLabel" from the PowerShellForGitHub project.

.EXAMPLE
Remove-GitHubLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Confirm:$false

Removes the label called "TestLabel" from the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
DefaultParameterSetName='Elements',
ConfirmImpact="High")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[Alias('Delete-GitHubLabel')]
param(
Expand Down Expand Up @@ -354,18 +360,21 @@ function Remove-GitHubLabel
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
}

$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Name"
'Method' = 'Delete'
'Description' = "Deleting label $Name from $RepositoryName"
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}
if ($PSCmdlet.ShouldProcess($Name, "Remove label"))
{
$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Name"
'Method' = 'Delete'
'Description' = "Deleting label $Name from $RepositoryName"
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

return Invoke-GHRestMethod @params
return Invoke-GHRestMethod @params
}
}

function Update-GitHubLabel
Expand Down Expand Up @@ -611,7 +620,7 @@ function Set-GitHubLabel
if ($labelName -notin $labelNames)
{
# Remove label if it exists but is not in desired label list
$null = Remove-GitHubLabel -Name $labelName @commonParams
$null = Remove-GitHubLabel -Name $labelName @commonParams -Confirm:$false
}
}
}
Expand Down Expand Up @@ -860,10 +869,16 @@ function Remove-GitHubIssueLabel
Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Issue 1

Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project.

.EXAMPLE
Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Name TestLabel -Issue 1 -Confirm:$false

Removes the label called "TestLabel" from issue 1 in the PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
DefaultParameterSetName='Elements',
ConfirmImpact="High")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[Alias('Delete-GitHubLabel')]
param(
Expand Down Expand Up @@ -910,18 +925,21 @@ function Remove-GitHubIssueLabel
$description = "Deleting all labels from issue $Issue in $RepositoryName"
}

$params = @{
'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Name"
'Method' = 'Delete'
'Description' = $description
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}
if ($PSCmdlet.ShouldProcess($Name, "Remove label"))
{
$params = @{
'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Name"
'Method' = 'Delete'
'Description' = $description
'AcceptHeader' = 'application/vnd.github.symmetra-preview+json'
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

return Invoke-GHRestMethod @params
return Invoke-GHRestMethod @params
}
}

# A set of labels that a project might want to initially populate their repository with
Expand Down
31 changes: 20 additions & 11 deletions GitHubMilestones.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,16 @@ function Remove-GitHubMilestone
Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1

Deletes a Github milestone from the Microsoft\PowerShellForGitHub project.

.EXAMPLE
Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Confirm:$false

Deletes a Github milestone from the Microsoft\PowerShellForGitHub project. Will not prompt for confirmation, as -Confirm:$false was specified.
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
DefaultParameterSetName='Elements',
ConfirmImpact="High")]
[Alias('Delete-GitHubMilestone')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
param(
Expand Down Expand Up @@ -537,15 +543,18 @@ function Remove-GitHubMilestone
'Milestone' = (Get-PiiSafeString -PlainText $Milestone)
}

$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone"
'Method' = 'Delete'
'Description' = "Removing milestone $Milestone for $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}
if ($PSCmdlet.ShouldProcess($Milestone, "Remove milestone"))
{
$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone"
'Method' = 'Delete'
'Description' = "Removing milestone $Milestone for $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

return Invoke-GHRestMethod @params
return Invoke-GHRestMethod @params
}
}
5 changes: 5 additions & 0 deletions GitHubProjects.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ function Remove-GitHubProject

Remove project with ID '4387531'.

.EXAMPLE
Remove-GitHubProject -Project 4387531 -Confirm:$false

Remove project with ID '4387531' without prompting for confirmation.

.EXAMPLE
$project = Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub | Where-Object Name -eq 'TestProject'
Remove-GitHubProject -Project $project.id
Expand Down
30 changes: 19 additions & 11 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,16 @@ function Remove-GitHubRepository

.EXAMPLE
Remove-GitHubRepository -Uri https://github.com/You/YourRepoToDelete

.EXAMPLE
Remove-GitHubRepository -Uri https://github.com/You/YourRepoToDelete -Confirm:$false

Remove repository given uri without prompting for confirmation.
giuseppecampanelli marked this conversation as resolved.
Show resolved Hide resolved
#>
[CmdletBinding(
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
DefaultParameterSetName='Elements',
ConfirmImpact="High")]
[Alias('Delete-GitHubRepository')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
param(
Expand Down Expand Up @@ -250,18 +256,20 @@ function Remove-GitHubRepository
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
}
if ($PSCmdlet.ShouldProcess($RepositoryName, "Remove repository"))
{
$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName"
'Method' = 'Delete'
'Description' = "Deleting $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus)
}

$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName"
'Method' = 'Delete'
'Description' = "Deleting $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus)
return Invoke-GHRestMethod @params
}

return Invoke-GHRestMethod @params
}

function Get-GitHubRepository
Expand Down
16 changes: 8 additions & 8 deletions Tests/GitHubAnalytics.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ try
}
}

$null = Remove-GitHubRepository -Uri ($repo.svn_url)
$null = Remove-GitHubRepository -Uri ($repo.svn_url) -Confirm:$false
}

Describe 'Obtaining repository with biggest number of issues' {
Expand Down Expand Up @@ -98,8 +98,8 @@ try
}
}

$null = Remove-GitHubRepository -Uri ($repo1.svn_url)
$null = Remove-GitHubRepository -Uri ($repo2.svn_url)
$null = Remove-GitHubRepository -Uri ($repo1.svn_url) -Confirm:$false
$null = Remove-GitHubRepository -Uri ($repo2.svn_url) -Confirm:$false
}


Expand Down Expand Up @@ -192,7 +192,7 @@ try
@($collaborators).Count | Should be 1
}

$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName
$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false
}
}

Expand All @@ -207,7 +207,7 @@ try
@($contributors).Count | Should be 1
}

$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName
$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false
}

if ($script:accessTokenConfigured)
Expand Down Expand Up @@ -253,7 +253,7 @@ try
(@($current).Count - @($original).Count) | Should be 1
}

$null = Remove-GitHubRepository -Uri $repo.svn_url
$null = Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false
}

Describe 'Getting unique contributors from contributors array' {
Expand All @@ -271,7 +271,7 @@ try
@($uniqueContributors).Count | Should be 1
}

$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName
$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false
}

Describe 'Getting repository name from url' {
Expand Down Expand Up @@ -308,7 +308,7 @@ try
@($branches[0].name) | Should be "master"
}

$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName
$null = Remove-GitHubRepository -OwnerName $script:ownerName -RepositoryName $repositoryName -Confirm:$false
}
}
finally
Expand Down
Loading