From 9e811ea368338827bc494ef35524031021657145 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 28 Jun 2020 11:41:12 +0100 Subject: [PATCH 01/13] ShouldProcess Updates --- GitHubAnalytics.ps1 | 10 +- GitHubAssignees.ps1 | 54 ++++---- GitHubBranches.ps1 | 5 +- GitHubConfiguration.ps1 | 103 ++++++++------- GitHubContents.ps1 | 153 +++++++++++----------- GitHubCore.ps1 | 12 +- GitHubEvents.ps1 | 5 +- GitHubIssueComments.ps1 | 53 ++++---- GitHubIssues.ps1 | 50 +++++--- GitHubLabels.ps1 | 131 ++++++++++++------- GitHubMilestones.ps1 | 49 ++++--- GitHubMiscellaneous.ps1 | 20 +-- GitHubOrganizations.ps1 | 6 +- GitHubProjectCards.ps1 | 59 +++++---- GitHubProjectColumns.ps1 | 65 ++++++---- GitHubProjects.ps1 | 52 ++++---- GitHubPullRequests.ps1 | 15 ++- GitHubRepositories.ps1 | 246 +++++++++++++++++++----------------- GitHubRepositoryForks.ps1 | 15 ++- GitHubRepositoryTraffic.ps1 | 20 +-- GitHubTeams.ps1 | 10 +- GitHubUsers.ps1 | 18 +-- Helpers.ps1 | 7 +- Telemetry.ps1 | 13 +- 24 files changed, 627 insertions(+), 544 deletions(-) diff --git a/GitHubAnalytics.ps1 b/GitHubAnalytics.ps1 index 0ee2310b..4493aeeb 100644 --- a/GitHubAnalytics.ps1 +++ b/GitHubAnalytics.ps1 @@ -37,10 +37,7 @@ function Group-GitHubIssue $issues += Get-GitHubIssue -Uri 'https://github.com/powershell/xactivedirectory' $issues | Group-GitHubIssue -Weeks 12 -DateType Closed #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Weekly')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName='Weekly')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")] param ( @@ -165,10 +162,7 @@ function Group-GitHubPullRequest $pullRequests += Get-GitHubPullRequest -Uri 'https://github.com/powershell/xactivedirectory' $pullRequests | Group-GitHubPullRequest -Weeks 12 -DateType Closed #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Weekly')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName='Weekly')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")] param ( diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 3f3fbb06..126a489d 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -64,11 +64,8 @@ filter Get-GitHubAssignee Lists the available assignees for issues from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubUserTypeName})] - [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')] @@ -188,11 +185,8 @@ filter Test-GitHubAssignee Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType([bool])] - [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')] @@ -348,7 +342,6 @@ function Add-GitHubAssignee DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] [Alias('New-GitHubAssignee')] # Non-standard usage of the New verb, but done to avoid a breaking change post 0.14.0 - [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')] @@ -397,8 +390,6 @@ function Add-GitHubAssignee end { - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -426,6 +417,13 @@ function Add-GitHubAssignee 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + if (-not $PSCmdlet.ShouldProcess($Issue, "Add Assignee(s) $($userNames -join ',')")) + { + return + } + + Write-InvocationLog + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } } @@ -584,8 +582,6 @@ function Remove-GitHubAssignee end { - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -606,21 +602,25 @@ function Remove-GitHubAssignee $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($userNames -join ', ', "Remove assignee(s)")) + if (-not $PSCmdlet.ShouldProcess($Issue, "Remove assignee(s) $($userNames -join ', ')")) { - $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' = $script:symmetraAcceptHeader - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } - - return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) + return } + + Write-InvocationLog + + $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' = $script:symmetraAcceptHeader + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } } diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 502a785d..0657e7ed 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -96,11 +96,8 @@ filter Get-GitHubRepositoryBranch again. This tries to show some of the different types of objects you can pipe into this function. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubBranchTypeName})] - [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.")] [Alias('Get-GitHubBranch')] param( diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index 17ceacec..d215b3a6 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -41,8 +41,7 @@ function Initialize-GitHubConfiguration .NOTES Internal helper method. This is actually invoked at the END of this file. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param() $script:seenTokenWarningThisSession = $false @@ -196,7 +195,6 @@ function Set-GitHubConfiguration [CmdletBinding( PositionalBinding = $false, SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [ValidatePattern('^(?!https?:)(?!api\.)(?!www\.).*')] [string] $ApiHostName, @@ -267,6 +265,11 @@ function Set-GitHubConfiguration } } + if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration',' Save')) + { + return + } + if (-not $SessionOnly) { Save-GitHubConfiguration -Configuration $persistedConfig -Path $script:configurationFilePath @@ -355,8 +358,7 @@ function Save-GitHubConfiguration Serializes $config as a JSON object to 'c:\foo\config.json' #> - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [PSCustomObject] $Configuration, @@ -365,6 +367,11 @@ function Save-GitHubConfiguration [string] $Path ) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration','Save')) + { + return + } + $null = New-Item -Path $Path -Force ConvertTo-Json -InputObject $Configuration | Set-Content -Path $Path -Force -ErrorAction SilentlyContinue -ErrorVariable ev @@ -532,12 +539,14 @@ function Reset-GitHubConfiguration Set-TelemetryEvent -EventName Reset-GitHubConfiguration + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration','Reset')) + { + return + } + if (-not $SessionOnly) { - if ($PSCmdlet.ShouldProcess($script:configurationFilePath, "Delete configuration file")) - { - $null = Remove-Item -Path $script:configurationFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev - } + $null = Remove-Item -Path $script:configurationFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev if (($null -ne $ev) -and ($ev.Count -gt 0) -and ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) { @@ -580,8 +589,7 @@ function Read-GitHubConfiguration Returns back an object with the deserialized object contained in the specified file, if it exists and is valid. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param( [string] $Path ) @@ -634,8 +642,7 @@ function Import-GitHubConfiguration within a deserialized object from the content in $Path. The configuration object is then returned. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param( [string] $Path ) @@ -719,13 +726,17 @@ function Backup-GitHubConfiguration Writes the user's current configuration file to c:\foo\config.json. #> [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [string] $Path, [switch] $Force ) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Backup')) + { + return + } + # Make sure that the path that we're going to be storing the file exists. $null = New-Item -Path (Split-Path -Path $Path -Parent) -ItemType Directory -Force @@ -761,7 +772,6 @@ function Restore-GitHubConfiguration Makes the contents of c:\foo\config.json be the user's configuration for the module. #> [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [ValidateScript({ if (Test-Path -Path $_ -PathType Leaf) { $true } @@ -769,6 +779,11 @@ function Restore-GitHubConfiguration [string] $Path ) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Restore')) + { + return + } + # Make sure that the path that we're going to be storing the file exists. $null = New-Item -Path (Split-Path -Path $script:configurationFilePath -Parent) -ItemType Directory -Force @@ -814,8 +829,7 @@ function Resolve-ParameterWithDefaultConfigurationValue Checks to see if the NoStatus switch was provided by the user from the calling method. If so, uses that value. otherwise uses the DefaultNoStatus value currently configured. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param( $BoundParameters = (Get-Variable -Name PSBoundParameters -Scope 1 -ValueOnly), @@ -907,7 +921,6 @@ function Set-GitHubAuthentication authentication, but keeps it in memory only for the duration of this PowerShell session.. #> [CmdletBinding(SupportsShouldProcess)] - [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("PSUsePSCredentialType", "", Justification="The System.Management.Automation.Credential() attribute does not appear to work in PowerShell v4 which we need to support.")] param( [PSCredential] $Credential, @@ -915,8 +928,6 @@ function Set-GitHubAuthentication [switch] $SessionOnly ) - Write-InvocationLog - if (-not $PSBoundParameters.ContainsKey('Credential')) { $message = 'Please provide your GitHub API Token in the Password field. You can enter anything in the username field (it will be ignored).' @@ -937,15 +948,20 @@ function Set-GitHubAuthentication } $script:accessTokenCredential = $Credential + + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Set')) + { + return + } + + Write-InvocationLog + if (-not $SessionOnly) { - if ($PSCmdlet.ShouldProcess("Store API token as a SecureString in a local file")) - { - $null = New-Item -Path $script:accessTokenFilePath -Force - $script:accessTokenCredential.Password | - ConvertFrom-SecureString | - Set-Content -Path $script:accessTokenFilePath -Force - } + $null = New-Item -Path $script:accessTokenFilePath -Force + $script:accessTokenCredential.Password | + ConvertFrom-SecureString | + Set-Content -Path $script:accessTokenFilePath -Force } } @@ -980,28 +996,27 @@ function Clear-GitHubAuthentication [switch] $SessionOnly ) - Write-InvocationLog - Set-TelemetryEvent -EventName Clear-GitHubAuthentication - if ($PSCmdlet.ShouldProcess("Clear memory cache")) + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Clear')) { - $script:accessTokenCredential = $null + return } + Write-InvocationLog + + $script:accessTokenCredential = $null + if (-not $SessionOnly) { - if ($PSCmdlet.ShouldProcess("Clear file-based cache")) - { - Remove-Item -Path $script:accessTokenFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev + Remove-Item -Path $script:accessTokenFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev - if (($null -ne $ev) -and - ($ev.Count -gt 0) -and - ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) - { - $message = "Experienced a problem trying to remove the file that persists the Access Token [$script:accessTokenFilePath]." - Write-Log -Message $message -Level Warning -Exception $ev[0] - } + if (($null -ne $ev) -and + ($ev.Count -gt 0) -and + ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) + { + $message = "Experienced a problem trying to remove the file that persists the Access Token [$script:accessTokenFilePath]." + Write-Log -Message $message -Level Warning -Exception $ev[0] } } @@ -1033,9 +1048,8 @@ function Get-AccessToken .OUTPUTS System.String #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Justification="For back-compat with v0.1.0, this still supports the deprecated method of using a global variable for storing the Access Token.")] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [OutputType([String])] param( [string] $AccessToken @@ -1112,8 +1126,7 @@ function Test-GitHubAuthenticationConfigured Returns $true if the session is authenticated; $false otherwise #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] [OutputType([Boolean])] param() diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 85b290f8..c39bbbb3 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -105,12 +105,9 @@ Unable to specify Path as ValueFromPipeline because a Repository object may be incorrectly coerced into a string used for Path, thus confusing things. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName = 'Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType([String])] [OutputType({$script:GitHubContentTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -427,94 +424,96 @@ filter Set-GitHubContent $hashBody['sha'] = $Sha } - if ($PSCmdlet.ShouldProcess( + if (-not $PSCmdlet.ShouldProcess( "$BranchName branch of $RepositoryName", "Set GitHub Contents on $Path")) { - Write-InvocationLog - - $params = @{ - UriFragment = $uriFragment - Description = "Writing content for $Path in the $BranchName branch of $RepositoryName" - Body = (ConvertTo-Json -InputObject $hashBody) - Method = 'Put' - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` - -ConfigValueName DefaultNoStatus) - } + return + } + + Write-InvocationLog + + $params = @{ + UriFragment = $uriFragment + Description = "Writing content for $Path in the $BranchName branch of $RepositoryName" + Body = (ConvertTo-Json -InputObject $hashBody) + Method = 'Put' + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` + -ConfigValueName DefaultNoStatus) + } - try + try + { + return (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties) + } + catch + { + $overwriteShaRequired = $false + + # Temporary code to handle current differences in exception object between PS5 and PS7 + if ($PSVersionTable.PSedition -eq 'Core') { - return (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties) + $errorMessage = ($_.ErrorDetails.Message | ConvertFrom-Json).message -replace '\n',' ' -replace '\"','"' + if (($_.Exception -is [Microsoft.PowerShell.Commands.HttpResponseException]) -and + ($errorMessage -eq 'Invalid request. "sha" wasn''t supplied.')) + { + $overwriteShaRequired = $true + } + else + { + throw $_ + } } - catch + else { - $overwriteShaRequired = $false - - # Temporary code to handle current differences in exception object between PS5 and PS7 - if ($PSVersionTable.PSedition -eq 'Core') + $errorMessage = $_.Exception.Message -replace '\n',' ' -replace '\"','"' + if ($errorMessage -like '*Invalid request. "sha" wasn''t supplied.*') { - $errorMessage = ($_.ErrorDetails.Message | ConvertFrom-Json).message -replace '\n',' ' -replace '\"','"' - if (($_.Exception -is [Microsoft.PowerShell.Commands.HttpResponseException]) -and - ($errorMessage -eq 'Invalid request. "sha" wasn''t supplied.')) - { - $overwriteShaRequired = $true - } - else - { - throw $_ - } + $overwriteShaRequired = $true } else { - $errorMessage = $_.Exception.Message -replace '\n',' ' -replace '\"','"' - if ($errorMessage -like '*Invalid request. "sha" wasn''t supplied.*') - { - $overwriteShaRequired = $true - } - else - { - throw $_ - } + throw $_ + } + } + + if ($overwriteShaRequired) + { + # Get SHA from current file + $getGitHubContentParms = @{ + Path = $Path + OwnerName = $OwnerName + RepositoryName = $RepositoryName + } + + if ($PSBoundParameters.ContainsKey('BranchName')) + { + $getGitHubContentParms['BranchName'] = $BranchName } - if ($overwriteShaRequired) + if ($PSBoundParameters.ContainsKey('AccessToken')) { - # Get SHA from current file - $getGitHubContentParms = @{ - Path = $Path - OwnerName = $OwnerName - RepositoryName = $RepositoryName - } - - if ($PSBoundParameters.ContainsKey('BranchName')) - { - $getGitHubContentParms['BranchName'] = $BranchName - } - - if ($PSBoundParameters.ContainsKey('AccessToken')) - { - $getGitHubContentParms['AccessToken'] = $AccessToken - } - - if ($PSBoundParameters.ContainsKey('NoStatus')) - { - $getGitHubContentParms['NoStatus'] = $NoStatus - } - - $object = Get-GitHubContent @getGitHubContentParms - - $hashBody['sha'] = $object.sha - $params['body'] = ConvertTo-Json -InputObject $hashBody - - $message = 'Replacing the content of an existing file requires the current SHA ' + - 'of that file. Retrieving the SHA now.' - Write-Log -Level Verbose -Message $message - - return (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties) + $getGitHubContentParms['AccessToken'] = $AccessToken } + + if ($PSBoundParameters.ContainsKey('NoStatus')) + { + $getGitHubContentParms['NoStatus'] = $NoStatus + } + + $object = Get-GitHubContent @getGitHubContentParms + + $hashBody['sha'] = $object.sha + $params['body'] = ConvertTo-Json -InputObject $hashBody + + $message = 'Replacing the content of an existing file requires the current SHA ' + + 'of that file. Retrieving the SHA now.' + Write-Log -Level Verbose -Message $message + + return (Invoke-GHRestMethod @params | Add-GitHubContentAdditionalProperties) } } } diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 4ea6fabd..37228a89 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -118,7 +118,7 @@ function Invoke-GHRestMethod This wraps Invoke-WebRequest as opposed to Invoke-RestMethod because we want access to the headers that are returned in the response, and Invoke-RestMethod drops those headers. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] param( [Parameter(Mandatory)] [string] $UriFragment, @@ -256,11 +256,6 @@ function Invoke-GHRestMethod $headers.Add("Content-Type", $ContentType) } - if (-not $PSCmdlet.ShouldProcess($url, "Invoke-WebRequest")) - { - return - } - $originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol # When $Save is in use, we need to remember what file we're saving the result to. @@ -633,7 +628,7 @@ function Invoke-GHRestMethodMultipleResult but the request happens in the foreground and there is no additional status shown to the user until a response is returned from the REST request. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [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.")] [OutputType([Object[]])] param( @@ -918,8 +913,7 @@ function Resolve-RepositoryElements .OUTPUTS [PSCustomObject] - The OwnerName and RepositoryName elements to be used #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="This was the most accurate name that I could come up with. Internal only anyway.")] param ( diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 2dc597db..05764137 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -71,11 +71,8 @@ filter Get-GitHubEvent Get the events for the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='RepositoryElements')] + [CmdletBinding(DefaultParameterSetName = 'RepositoryElements')] [OutputType({$script:GitHubEventTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 48ec9447..4d19bf46 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -120,12 +120,9 @@ filter Get-GitHubIssueComment passing it in via the pipeline. This shows some of the different types of objects you can pipe into this function. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='RepositoryElements')] + [CmdletBinding(DefaultParameterSetName = 'RepositoryElements')] [Alias('Get-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 [OutputType({$script:GitHubIssueCommentTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -364,7 +361,6 @@ filter New-GitHubIssueComment DefaultParameterSetName='Elements')] [Alias('New-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 [OutputType({$script:GitHubIssueCommentTypeName})] - [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')] @@ -397,8 +393,6 @@ filter New-GitHubIssueComment [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -413,6 +407,13 @@ filter New-GitHubIssueComment 'body' = $Body } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Create GitHub Issue Comment')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/comments" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -509,7 +510,6 @@ filter Set-GitHubIssueComment DefaultParameterSetName='Elements')] [Alias('Set-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 [OutputType({$script:GitHubIssueCommentTypeName})] - [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')] @@ -542,8 +542,6 @@ filter Set-GitHubIssueComment [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -558,6 +556,13 @@ filter Set-GitHubIssueComment 'body' = $Body } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Create GitHub Issue Comment')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -679,8 +684,6 @@ filter Remove-GitHubIssueComment [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -696,20 +699,24 @@ filter Remove-GitHubIssueComment $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Comment, "Remove comment")) + if (-not $PSCmdlet.ShouldProcess($Comment, 'Remove GitHub Issue Comment')) { - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" - 'Method' = 'Delete' - 'Description' = "Removing comment $Comment for $RepositoryName" - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } + + Write-InvocationLog - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" + 'Method' = 'Delete' + 'Description' = "Removing comment $Comment for $RepositoryName" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Add-GitHubIssueCommentAdditionalProperties diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index afd90bcf..fb25303d 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -147,11 +147,8 @@ filter Get-GitHubIssue Gets every issue in the microsoft\PowerShellForGitHub repository that is assigned to Octocat. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubIssueTypeName})] - [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, @@ -444,11 +441,8 @@ filter Get-GitHubIssueTimeline .EXAMPLE Get-GitHubIssueTimeline -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 24 #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubEventTypeName})] - [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')] @@ -588,7 +582,6 @@ filter New-GitHubIssue SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] - [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, @@ -625,8 +618,6 @@ filter New-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -645,6 +636,13 @@ filter New-GitHubIssue if ($PSBoundParameters.ContainsKey('Milestone')) { $hashBody['milestone'] = $Milestone } if ($PSBoundParameters.ContainsKey('Label')) { $hashBody['labels'] = @($Label) } + if (-not $PSCmdlet.ShouldProcess($Title, 'Create GitHub Issue')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -759,7 +757,6 @@ filter Set-GitHubIssue DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] [Alias('Update-GitHubIssue')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [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, @@ -801,8 +798,6 @@ filter Set-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -828,6 +823,13 @@ filter Set-GitHubIssue } } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Update GitHub Issue')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -906,7 +908,6 @@ filter Lock-GitHubIssue [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [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, @@ -935,8 +936,6 @@ filter Lock-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -963,6 +962,13 @@ filter Lock-GitHubIssue $hashBody['lock_reason'] = $reasonConverter[$Reason] } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Lock GitHub Issue')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1038,7 +1044,6 @@ filter Unlock-GitHubIssue [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [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,8 +1070,6 @@ filter Unlock-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1076,6 +1079,13 @@ filter Unlock-GitHubIssue 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Unlock GitHub Issue')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" 'Method' = 'Delete' diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 22cf446f..66cef12f 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -87,11 +87,8 @@ filter Get-GitHubLabel input. For the time being, the ParameterSets have been simplified and the validation of parameter combinations is happening within the function itself. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='NameUri')] + [CmdletBinding(DefaultParameterSetName = 'NameUri')] [OutputType({$script:GitHubLabelTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -269,7 +266,6 @@ filter New-GitHubLabel SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubLabelTypeName})] - [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')] @@ -303,8 +299,6 @@ filter New-GitHubLabel [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -327,6 +321,13 @@ filter New-GitHubLabel 'description' = $Description } + if (-not $PSCmdlet.ShouldProcess($Label, 'Create GitHub Label')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -459,8 +460,6 @@ filter Remove-GitHubLabel [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -475,21 +474,25 @@ filter Remove-GitHubLabel $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Label, "Remove label")) + if (-not $PSCmdlet.ShouldProcess($Label, 'Remove GitHub label')) { - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" - 'Method' = 'Delete' - 'Description' = "Deleting label $Label from $RepositoryName" - 'AcceptHeader' = $script:symmetraAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params + Write-InvocationLog + + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" + 'Method' = 'Delete' + 'Description' = "Deleting label $Label from $RepositoryName" + 'AcceptHeader' = $script:symmetraAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Set-GitHubLabel @@ -573,7 +576,6 @@ filter Set-GitHubLabel DefaultParameterSetName='Elements')] [OutputType({$script:GitHubLabelTypeName})] [Alias('Update-GitHubLabel')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [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, @@ -608,8 +610,6 @@ filter Set-GitHubLabel [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -631,6 +631,13 @@ filter Set-GitHubLabel if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } if ($PSBoundParameters.ContainsKey('Color')) { $hashBody['color'] = $Color } + if (-not $PSCmdlet.ShouldProcess($Label, 'Update GitHub Label')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -724,7 +731,6 @@ filter Initialize-GitHubLabel [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [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')] @@ -770,17 +776,39 @@ filter Initialize-GitHubLabel $existingLabels = Get-GitHubLabel @commonParams $existingLabelNames = $existingLabels.name + if (-not $PSCmdlet.ShouldProcess(($Label -join ', '), 'Set GitHub Label')) + { + return + } + + Write-InvocationLog + foreach ($labelToConfigure in $Label) { if ($labelToConfigure.name -notin $existingLabelNames) { # Create label if it doesn't exist - $null = New-GitHubLabel -Label $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $newGitHubLabelParms = @{ + Label = $labelToConfigure.name + Color = $labelToConfigure.color + Confirm = $false + WhatIf = $false + } + + $null = New-GitHubLabel @newGitHubLabelParms @commonParams } else { # Update label's color if it already exists - $null = Set-GitHubLabel -Label $labelToConfigure.name -NewName $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $setGitHubLabelParms = @{ + Label = $labelToConfigure.name + NewName = $labelToConfigure.name + Color = $labelToConfigure.color + Confirm = $false + WhatIf = $false + } + + $null = Set-GitHubLabel @setGitHubLabelParms @commonParams } } @@ -789,7 +817,13 @@ filter Initialize-GitHubLabel if ($labelName -notin $labelNames) { # Remove label if it exists but is not in desired label list - $null = Remove-GitHubLabel -Label $labelName @commonParams -Confirm:$false + $removeGitHubLabelParms = @{ + Label = $labelName + Confirm = $false + WhatIf = $false + } + + $null = Remove-GitHubLabel @removeGitHubLabelParms @commonParams } } } @@ -867,7 +901,6 @@ function Add-GitHubIssueLabel SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubLabelTypeName})] - [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( @@ -921,8 +954,6 @@ function Add-GitHubIssueLabel end { - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -937,6 +968,13 @@ function Add-GitHubIssueLabel 'labels' = $labelNames } + if (-not $PSCmdlet.ShouldProcess(($Label -join ', '), 'Add GitHub Issue Label')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1054,7 +1092,6 @@ function Set-GitHubIssueLabel DefaultParameterSetName='Elements', ConfirmImpact='High')] [OutputType({$script:GitHubLabelTypeName})] - [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')] @@ -1123,11 +1160,13 @@ function Set-GitHubIssueLabel $ConfirmPreference = 'None' } - if (($labelNames.Count -eq 0) -and (-not $PSCmdlet.ShouldProcess($Issue, "Remove all labels from issue"))) + if (-not $PSCmdlet.ShouldProcess(($Label -join ', '), 'Set GitHub Issue Label')) { return } + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1287,21 +1326,23 @@ filter Remove-GitHubIssueLabel $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Label, "Remove label")) + if (-not $PSCmdlet.ShouldProcess($Label, 'Remove GitHub Issue label')) { - $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Label" - 'Method' = 'Delete' - 'Description' = $description - 'AcceptHeader' = $script:symmetraAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Label" + 'Method' = 'Delete' + 'Description' = $description + 'AcceptHeader' = $script:symmetraAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Add-GitHubLabelAdditionalProperties diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 7326bf5e..c983f45a 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -83,10 +83,7 @@ filter Get-GitHubMilestone Get-GitHubMilestone -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -Milestone 1 Get milestone number 1 for the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='RepositoryElements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName = 'RepositoryElements')] param( [Parameter( Mandatory, @@ -299,7 +296,6 @@ filter New-GitHubMilestone [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -340,8 +336,6 @@ filter New-GitHubMilestone [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -380,6 +374,13 @@ filter New-GitHubMilestone $hashBody.add('due_on', $dueOnFormattedTime) } + if (-not $PSCmdlet.ShouldProcess($Title, 'Create GitHub Milestone')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -482,7 +483,6 @@ filter Set-GitHubMilestone [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -532,8 +532,6 @@ filter Set-GitHubMilestone [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -573,6 +571,13 @@ filter Set-GitHubMilestone $hashBody.add('due_on', $dueOnFormattedTime) } + if (-not $PSCmdlet.ShouldProcess($Milestone, 'Set GitHub Milestone')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -717,20 +722,22 @@ filter Remove-GitHubMilestone $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Milestone, "Remove milestone")) + if (-not $PSCmdlet.ShouldProcess($Milestone, 'Remove GitHub 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 + } - return Invoke-GHRestMethod @params + $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 } filter Add-GitHubMilestoneAdditionalProperties diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index a90a0a41..07cda624 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -62,9 +62,8 @@ function Get-GitHubRateLimit .EXAMPLE Get-GitHubRateLimit #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubRateLimitTypeName})] - [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( [string] $AccessToken, @@ -135,9 +134,8 @@ function ConvertFrom-GitHubMarkdown Returns back '

Bolded Text

' #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType([String])] - [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( @@ -276,12 +274,9 @@ filter Get-GitHubLicense [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result.content)) #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='All')] + [CmdletBinding(DefaultParameterSetName = 'All')] [OutputType({$script:GitHubLicenseTypeName})] [OutputType({$script:GitHubContentTypeName})] - [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, @@ -410,9 +405,8 @@ function Get-GitHubEmoji .EXAMPLE Get-GitHubEmoji #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubEmojiTypeName})] - [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( [string] $AccessToken, @@ -517,9 +511,8 @@ filter Get-GitHubCodeOfConduct [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result.content)) #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubCodeOfConductTypeName})] - [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, @@ -648,9 +641,8 @@ filter Get-GitHubGitIgnore Returns the content of the VisualStudio.gitignore template. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubGitignoreTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( ValueFromPipeline, diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index 95e81e88..2a02a925 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -41,9 +41,8 @@ filter Get-GitHubOrganizationMember .EXAMPLE Get-GitHubOrganizationMember -OrganizationName PowerShell #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubUserTypeName})] - [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 ( @@ -113,9 +112,8 @@ filter Test-GitHubOrganizationMember .EXAMPLE Test-GitHubOrganizationMember -OrganizationName PowerShell -UserName Octocat #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType([bool])] - [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 ( diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index ed911fa5..87b48146 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -59,11 +59,8 @@ filter Get-GitHubProjectCard Gets the card with ID 999999. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName = 'Card')] + [CmdletBinding(DefaultParameterSetName = 'Card')] [OutputType({$script:GitHubProjectCardTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -194,7 +191,6 @@ filter New-GitHubProjectCard SupportsShouldProcess, DefaultParameterSetName = 'Note')] [OutputType({$script:GitHubProjectCardTypeName})] - [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( @@ -226,8 +222,6 @@ filter New-GitHubProjectCard [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column/cards" @@ -260,6 +254,13 @@ filter New-GitHubProjectCard } } + if (-not $PSCmdlet.ShouldProcess($Column, 'Create GitHub Project Card')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -331,7 +332,6 @@ filter Set-GitHubProjectCard SupportsShouldProcess, DefaultParameterSetName = 'Note')] [OutputType({$script:GitHubProjectCardTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -353,8 +353,6 @@ filter Set-GitHubProjectCard [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "/projects/columns/cards/$Card" @@ -380,6 +378,13 @@ filter Set-GitHubProjectCard $hashBody.add('archived', $false) } + if (-not $PSCmdlet.ShouldProcess($Card, 'Set GitHub Project Card')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -468,21 +473,23 @@ filter Remove-GitHubProjectCard $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Card, "Remove card")) + if (-not $PSCmdlet.ShouldProcess($Card, 'Remove GitHub Project Card')) { - $params = @{ - 'UriFragment' = $uriFragment - 'Description' = $description - 'AccessToken' = $AccessToken - 'Method' = 'Delete' - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = $script:inertiaAcceptHeader - } + return + } - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'AccessToken' = $AccessToken + 'Method' = 'Delete' + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + 'AcceptHeader' = $script:inertiaAcceptHeader } + + return Invoke-GHRestMethod @params } filter Move-GitHubProjectCard @@ -545,7 +552,6 @@ filter Move-GitHubProjectCard the column with ID 123456. #> [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -604,6 +610,13 @@ filter Move-GitHubProjectCard $hashBody.add('column_id', $Column) } + if (-not $PSCmdlet.ShouldProcess($Card, 'Move GitHub Project Card')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index f65cd309..210b48af 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -49,11 +49,8 @@ filter Get-GitHubProjectColumn Get the column with ID 999999. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName = 'Column')] + [CmdletBinding(DefaultParameterSetName = 'Column')] [OutputType({$script:GitHubProjectColumnTypeName})] - [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( @@ -151,7 +148,6 @@ filter New-GitHubProjectColumn #> [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubProjectColumnTypeName})] - [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( @@ -172,8 +168,6 @@ filter New-GitHubProjectColumn [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $telemetryProperties['Project'] = Get-PiiSafeString -PlainText $Project @@ -184,6 +178,13 @@ filter New-GitHubProjectColumn 'name' = $ColumnName } + if (-not $PSCmdlet.ShouldProcess($ColumnName, 'Create GitHub Project Column')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -237,7 +238,6 @@ filter Set-GitHubProjectColumn #> [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubProjectColumnTypeName})] - [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( @@ -255,8 +255,6 @@ filter Set-GitHubProjectColumn [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column" @@ -266,6 +264,13 @@ filter Set-GitHubProjectColumn 'name' = $ColumnName } + if (-not $PSCmdlet.ShouldProcess($ColumnName, 'Set GitHub Project Column')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -343,8 +348,6 @@ filter Remove-GitHubProjectColumn [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column" @@ -355,21 +358,25 @@ filter Remove-GitHubProjectColumn $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Column, "Remove column")) + if (-not $PSCmdlet.ShouldProcess($Column, 'Remove GitHub Project Column')) { - $params = @{ - 'UriFragment' = $uriFragment - 'Description' = $description - 'AccessToken' = $AccessToken - 'Method' = 'Delete' - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = $script:inertiaAcceptHeader - } + return + } - return Invoke-GHRestMethod @params + Write-InvocationLog + + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'AccessToken' = $AccessToken + 'Method' = 'Delete' + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + 'AcceptHeader' = $script:inertiaAcceptHeader } + + return Invoke-GHRestMethod @params } filter Move-GitHubProjectColumn @@ -423,7 +430,6 @@ filter Move-GitHubProjectColumn Moves the project column with ID 999999 to the position after column with ID 888888. #> [CmdletBinding(SupportsShouldProcess)] - [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( @@ -443,8 +449,6 @@ filter Move-GitHubProjectColumn [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column/moves" @@ -473,6 +477,13 @@ filter Move-GitHubProjectColumn 'position' = $Position } + if (-not $PSCmdlet.ShouldProcess($ColumnName, 'Move GitHub Project Column')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 87566375..90a884d1 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -100,11 +100,8 @@ filter Get-GitHubProject Get a project by id, with this parameter you don't need any other information. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName = 'Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubPullRequestTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -309,7 +306,6 @@ filter New-GitHubProject SupportsShouldProcess, DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubPullRequestTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -394,6 +390,13 @@ filter New-GitHubProject $hashBody.add('body', $Description) } + if (-not $PSCmdlet.ShouldProcess($ProjectName, 'Create GitHub Project')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -479,7 +482,6 @@ filter Set-GitHubProject #> [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubPullRequestTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -503,8 +505,6 @@ filter Set-GitHubProject [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "projects/$Project" @@ -536,6 +536,13 @@ filter Set-GitHubProject $apiDescription += ", organization_permission to '$OrganizationPermission'" } + if (-not $PSCmdlet.ShouldProcess($Project, 'Set GitHub Project')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -632,8 +639,6 @@ filter Remove-GitHubProject [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "projects/$Project" @@ -644,22 +649,25 @@ filter Remove-GitHubProject $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($project, "Remove project")) + if (-not $PSCmdlet.ShouldProcess($Project, 'Remove GitHub Project')) { - $params = @{ - 'UriFragment' = $uriFragment - 'Description' = $description - 'AccessToken' = $AccessToken - 'Method' = 'Delete' - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - 'AcceptHeader' = $script:inertiaAcceptHeader - } + return + } - return Invoke-GHRestMethod @params + Write-InvocationLog + + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'AccessToken' = $AccessToken + 'Method' = 'Delete' + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + 'AcceptHeader' = $script:inertiaAcceptHeader } + return Invoke-GHRestMethod @params } filter Add-GitHubProjectAdditionalProperties diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 50b87fea..e0e5fc5e 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -90,10 +90,7 @@ filter Get-GitHubPullRequest .EXAMPLE $pullRequests = Get-GitHubPullRequest -OwnerName microsoft -RepositoryName PowerShellForGitHub -State Closed #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName = 'Elements')] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -300,7 +297,6 @@ filter New-GitHubPullRequest New-GitHubPullRequest -Uri 'https://github.com/PowerShell/PSScriptAnalyzer' -Issue 642 -Head simple-test -HeadOwner octocat -Base development -Draft #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements_Title')] @@ -365,8 +361,6 @@ filter New-GitHubPullRequest [switch] $NoStatus ) - Write-InvocationLog - if (-not [string]::IsNullOrWhiteSpace($HeadOwner)) { if ($Head.Contains(':')) @@ -426,6 +420,13 @@ filter New-GitHubPullRequest $acceptHeader = 'application/vnd.github.shadow-cat-preview+json' } + if (-not $PSCmdlet.ShouldProcess($Title, 'Create GitHub Pull Request')) + { + return + } + + Write-InvocationLog + $restParams = @{ 'UriFragment' = $uriFragment 'Method' = 'Post' diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index e198ef29..aa3bea15 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -127,7 +127,6 @@ filter New-GitHubRepository #> [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubRepositoryTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -174,8 +173,6 @@ filter New-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $telemetryProperties = @{ 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } @@ -215,6 +212,13 @@ filter New-GitHubRepository if ($PSBoundParameters.ContainsKey('DeleteBranchOnMerge')) { $hashBody['delete_branch_on_merge'] = $DeleteBranchOnMerge.ToBool() } if ($PSBoundParameters.ContainsKey('IsTemplate')) { $hashBody['is_template'] = $IsTemplate.ToBool() } + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Create GitHub Repository')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -318,9 +322,6 @@ filter New-GitHubRepositoryFromTemplate SupportsShouldProcess, PositionalBinding = $false)] [OutputType({$script:GitHubRepositoryTypeName})] - [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, @@ -384,6 +385,15 @@ filter New-GitHubRepositoryFromTemplate if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } if ($PSBoundParameters.ContainsKey('Private')) { $hashBody['private'] = $Private.ToBool() } + if (-not $PSCmdlet.ShouldProcess( + $TargetRepositoryName, + "Create GitHub Repository From Template $RepositoryName")) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -503,8 +513,6 @@ filter Remove-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -519,20 +527,24 @@ filter Remove-GitHubRepository $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($RepositoryName, "Remove repository")) + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Remove GitHub Repository')) { - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName" - 'Method' = 'Delete' - 'Description' = "Deleting $RepositoryName" - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params + Write-InvocationLog + + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName" + 'Method' = 'Delete' + 'Description' = "Deleting $RepositoryName" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Get-GitHubRepository @@ -660,12 +672,8 @@ filter Get-GitHubRepository Gets all of the repositories in the PowerShell organization. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='AuthenticatedUser')] + [CmdletBinding(DefaultParameterSetName = 'AuthenticatedUser')] [OutputType({$script:GitHubRepositoryTypeName})] - [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( @@ -993,7 +1001,6 @@ filter Rename-GitHubRepository DefaultParameterSetName='Uri', ConfirmImpact="High")] [OutputType({$script:GitHubRepositoryTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -1157,7 +1164,6 @@ filter Set-GitHubRepository ConfirmImpact='High')] [OutputType({$script:GitHubRepositoryTypeName})] [Alias('Update-GitHubRepository')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [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, @@ -1208,8 +1214,6 @@ filter Set-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1219,11 +1223,6 @@ filter Set-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($Force -and (-not $Confirm)) - { - $ConfirmPreference = 'None' - } - $hashBody = @{} if ($PSBoundParameters.ContainsKey('NewName')) @@ -1251,6 +1250,18 @@ filter Set-GitHubRepository if ($PSBoundParameters.ContainsKey('IsTemplate')) { $hashBody['is_template'] = $IsTemplate.ToBool() } if ($PSBoundParameters.ContainsKey('Archived')) { $hashBody['archived'] = $Archived.ToBool() } + if ($Force -and (-not $Confirm)) + { + $ConfirmPreference = 'None' + } + + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Update GitHub Repository')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1326,11 +1337,8 @@ filter Get-GitHubRepositoryTopic .EXAMPLE Get-GitHubRepositoryTopic -Uri https://github.com/PowerShell/PowerShellForGitHub #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryTopicTypeName})] - [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')] @@ -1457,7 +1465,6 @@ function Set-GitHubRepositoryTopic SupportsShouldProcess, DefaultParameterSetName='ElementsName')] [OutputType({$script:GitHubRepositoryTopicTypeName})] - [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='ElementsName')] [Parameter(ParameterSetName='ElementsClear')] @@ -1517,8 +1524,6 @@ function Set-GitHubRepositoryTopic end { - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1542,6 +1547,15 @@ function Set-GitHubRepositoryTopic 'names' = $topics } + if (-not $PSCmdlet.ShouldProcess( + $RepositoryName, + "Set GitHub Repository Topic $($Topic -join ', ')")) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/topics" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1637,12 +1651,9 @@ filter Get-GitHubRepositoryContributor Gets a list of contributors for the PowerShellForGithub repository including statistics. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryContributorTypeName})] [OutputType({$script:GitHubRepositoryContributorStatisticsTypeName})] - [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')] @@ -1790,11 +1801,8 @@ filter Get-GitHubRepositoryCollaborator Gets a list of collaborators for the PowerShellForGithub repository. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryCollaboratorTypeName})] - [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')] @@ -1907,11 +1915,8 @@ filter Get-GitHubRepositoryLanguage .EXAMPLE Get-GitHubRepositoryLanguage -Uri https://github.com/PowerShell/PowerShellForGitHub #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryLanguageTypeName})] - [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')] @@ -2016,11 +2021,8 @@ filter Get-GitHubRepositoryTag .EXAMPLE Get-GitHubRepositoryTag -Uri https://github.com/PowerShell/PowerShellForGitHub #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryTagTypeName})] - [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')] @@ -2134,7 +2136,6 @@ filter Move-GitHubRepositoryOwnership DefaultParameterSetName='Elements')] [OutputType({$script:GitHubRepositoryTypeName})] [Alias('Transfer-GitHubRepositoryOwnership')] - [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')] @@ -2161,8 +2162,6 @@ filter Move-GitHubRepositoryOwnership [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2178,6 +2177,15 @@ filter Move-GitHubRepositoryOwnership if ($TeamId.Count -gt 0) { $hashBody['team_ids'] = @($TeamId) } + if (-not $PSCmdlet.ShouldProcess( + $RepositoryName, + "Move GitHub Repository Ownership from $OwnerName to $NewOwnerName")) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/transfer" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -2438,24 +2446,26 @@ filter Enable-GitHubRepositoryVulnerabilityAlert 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($PSCmdlet.ShouldProcess($RepositoryName, 'Enable Vulnerability Alerts')) + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Enable Vulnerability Alerts')) { - Write-InvocationLog + return + } - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/vulnerability-alerts" - Description = "Enabling Vulnerability Alerts for $RepositoryName" - AcceptHeader = $script:dorianAcceptHeader - Method = 'Put' - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` - -Name NoStatus -ConfigValueName DefaultNoStatus) - } + Write-InvocationLog - Invoke-GHRestMethod @params | Out-Null + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/vulnerability-alerts" + Description = "Enabling Vulnerability Alerts for $RepositoryName" + AcceptHeader = $script:dorianAcceptHeader + Method = 'Put' + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` + -Name NoStatus -ConfigValueName DefaultNoStatus) } + + Invoke-GHRestMethod @params | Out-Null } filter Disable-GitHubRepositoryVulnerabilityAlert @@ -2555,24 +2565,26 @@ filter Disable-GitHubRepositoryVulnerabilityAlert 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($PSCmdlet.ShouldProcess($RepositoryName, 'Disable Vulnerability Alerts')) + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Disable Vulnerability Alerts')) { - Write-InvocationLog + return + } - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/vulnerability-alerts" - Description = "Disabling Vulnerability Alerts for $RepositoryName" - AcceptHeader = $script:dorianAcceptHeader - Method = 'Delete' - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` - -Name NoStatus -ConfigValueName DefaultNoStatus) - } + Write-InvocationLog - Invoke-GHRestMethod @params | Out-Null + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/vulnerability-alerts" + Description = "Disabling Vulnerability Alerts for $RepositoryName" + AcceptHeader = $script:dorianAcceptHeader + Method = 'Delete' + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` + -Name NoStatus -ConfigValueName DefaultNoStatus) } + + Invoke-GHRestMethod @params | Out-Null } filter Enable-GitHubRepositorySecurityFix @@ -2672,24 +2684,26 @@ filter Enable-GitHubRepositorySecurityFix 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($PSCmdlet.ShouldProcess($RepositoryName, 'Enable Automated Security Fixes')) + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Enable Automated Security Fixes')) { - Write-InvocationLog + return + } - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/automated-security-fixes" - Description = "Enabling Automated Security Fixes for $RepositoryName" - AcceptHeader = $script:londonAcceptHeader - Method = 'Put' - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` - -Name NoStatus -ConfigValueName DefaultNoStatus) - } + Write-InvocationLog - Invoke-GHRestMethod @params + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/automated-security-fixes" + Description = "Enabling Automated Security Fixes for $RepositoryName" + AcceptHeader = $script:londonAcceptHeader + Method = 'Put' + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` + -Name NoStatus -ConfigValueName DefaultNoStatus) } + + Invoke-GHRestMethod @params } filter Disable-GitHubRepositorySecurityFix @@ -2788,24 +2802,26 @@ filter Disable-GitHubRepositorySecurityFix 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($PSCmdlet.ShouldProcess($RepositoryName, 'Disable Automated Security Fixes')) + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Disable Automated Security Fixes')) { - Write-InvocationLog + return + } - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/automated-security-fixes" - Description = "Disabling Automated Security Fixes for $RepositoryName" - AcceptHeader = $script:londonAcceptHeader - Method = 'Delete' - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` - -Name NoStatus -ConfigValueName DefaultNoStatus) - } + Write-InvocationLog - Invoke-GHRestMethod @params | Out-Null + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/automated-security-fixes" + Description = "Disabling Automated Security Fixes for $RepositoryName" + AcceptHeader = $script:londonAcceptHeader + Method = 'Delete' + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` + -Name NoStatus -ConfigValueName DefaultNoStatus) } + + Invoke-GHRestMethod @params | Out-Null } filter Add-GitHubRepositoryAdditionalProperties diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 18a3ca31..08939878 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -63,11 +63,8 @@ filter Get-GitHubRepositoryFork Gets all of the forks for the microsoft\PowerShellForGitHub repository. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryTypeName})] - [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')] @@ -191,7 +188,6 @@ filter New-GitHubRepositoryFork SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubRepositoryTypeName})] - [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, @@ -213,8 +209,6 @@ filter New-GitHubRepositoryFork [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -232,6 +226,13 @@ filter New-GitHubRepositoryFork $getParams += "organization=$OrganizationName" } + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Forking GitHub Repository')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/forks`?" + ($getParams -join '&') 'Method' = 'Post' diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 606b64d6..3c5ba17e 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -69,11 +69,8 @@ filter Get-GitHubReferrerTraffic Get the top 10 referrers over the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubReferrerTrafficTypeName})] - [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')] @@ -185,11 +182,8 @@ filter Get-GitHubPathTraffic Get the top 10 popular contents over the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubPathTrafficTypeName})] - [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')] @@ -307,11 +301,8 @@ filter Get-GitHubViewTraffic Get the total number of views and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubViewTrafficTypeName})] - [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')] @@ -433,11 +424,8 @@ filter Get-GitHubCloneTraffic Get the total number of clones and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubCloneTrafficTypeName})] - [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')] diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 07d38454..33a632ed 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -72,11 +72,8 @@ filter Get-GitHubTeam .EXAMPLE Get-GitHubTeam -OrganizationName PowerShell #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubTeamTypeName})] - [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 ( @@ -212,11 +209,8 @@ filter Get-GitHubTeamMember .EXAMPLE $members = Get-GitHubTeamMember -Organization PowerShell -TeamName Everybody #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='ID')] + [CmdletBinding(DefaultParameterSetName = 'ID')] [OutputType({$script:GitHubUserTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param ( [Parameter( diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 16019b45..6e3678af 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -72,11 +72,8 @@ filter Get-GitHubUser Gets information on the current authenticated user. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='ListAndSearch')] + [CmdletBinding(DefaultParameterSetName = 'ListAndSearch')] [OutputType({$script:GitHubUserTypeName})] - [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( @@ -186,11 +183,8 @@ filter Get-GitHubUserContextualInformation Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 70 | Get-GitHubUserContextualInformation -User octocat #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='NoContext')] + [CmdletBinding(DefaultParameterSetName = 'NoContext')] [OutputType({$script:GitHubUserContextualInformationTypeName})] - [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( @@ -355,7 +349,6 @@ function Set-GitHubProfile [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubUserTypeName})] [Alias('Update-GitHubCurrentUser')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [string] $Name, @@ -387,6 +380,13 @@ function Set-GitHubProfile if ($PSBoundParameters.ContainsKey('Bio')) { $hashBody['bio'] = $Bio } if ($PSBoundParameters.ContainsKey('Hireable')) { $hashBody['hireable'] = $Hireable.ToBool() } + if (-not $PSCmdlet.ShouldProcess('Update Current GitHub User')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = 'user' 'Method' = 'Patch' diff --git a/Helpers.ps1 b/Helpers.ps1 index 5d1b5ef7..87526b1a 100644 --- a/Helpers.ps1 +++ b/Helpers.ps1 @@ -123,8 +123,7 @@ function Write-Log to make sense. In this case, the cmdlet should accumulate the messages and, at the end, include the exception information. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Justification="We need to be able to access the PID for logging purposes, and it is accessed via a global variable.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidOverwritingBuiltInCmdlets", "", Justification="Write-Log is an internal function being incorrectly exported by PSDesiredStateConfiguration. See PowerShell/PowerShell#7209")] param( @@ -248,7 +247,7 @@ function Write-Log } else { - $logFileMessage | Out-File -FilePath $Path -Append + $logFileMessage | Out-File -FilePath $Path -Append -WhatIf:$false -Confirm:$false } } } @@ -322,7 +321,7 @@ function Write-InvocationLog ExcludeParameter will always take precedence over RedactParameter. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] param( [Management.Automation.InvocationInfo] $Invocation = (Get-Variable -Name MyInvocation -Scope 1 -ValueOnly), diff --git a/Telemetry.ps1 b/Telemetry.ps1 index 857bc373..e5595ead 100644 --- a/Telemetry.ps1 +++ b/Telemetry.ps1 @@ -139,7 +139,8 @@ function Invoke-SendTelemetryEvent Invoke-* methods share a common base code. Leaving this as-is to make this file easier to share out with other PowerShell projects. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Justification="We use global variables sparingly and intentionally for module configuration, and employ a consistent naming convention.")] param( [Parameter(Mandatory)] [PSCustomObject] $TelemetryEvent @@ -296,8 +297,9 @@ function Set-TelemetryEvent Because of the short-running nature of this module, we always "flush" the events as soon as they have been posted to ensure that they make it to Application Insights. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', + Justification='Function is not state changing')] param( [Parameter(Mandatory)] [string] $EventName, @@ -392,8 +394,9 @@ function Set-TelemetryException Because of the short-running nature of this module, we always "flush" the events as soon as they have been posted to ensure that they make it to Application Insights. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', + Justification='Function is not state changing.')] param( [Parameter(Mandatory)] [System.Exception] $Exception, From 5af4a816d9c32d6a44edc1d9ba823f7fbd2828b4 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 28 Jun 2020 12:59:50 +0100 Subject: [PATCH 02/13] Update GitHubRepositories ShouldProcess --- GitHubRepositories.ps1 | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index aa3bea15..a10486ac 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1160,8 +1160,7 @@ filter Set-GitHubRepository #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements', - ConfirmImpact='High')] + DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryTypeName})] [Alias('Update-GitHubRepository')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 param( @@ -1224,16 +1223,13 @@ filter Set-GitHubRepository } $hashBody = @{} + $shouldProcessMessage = 'Update GitHub Repository' if ($PSBoundParameters.ContainsKey('NewName')) { - $existingName = if ($PSCmdlet.ParameterSetName -eq 'Uri') { $Uri } else { $OwnerName, $RepositoryName -join '/' } - if (-not $PSCmdlet.ShouldProcess($existingName, "Rename repository to '$NewName'")) - { - return - } - $hashBody['name'] = $NewName + $ConfirmPreference = 'Low' + $shouldProcessMessage = "Rename repository to '$NewName'" } if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } @@ -1255,7 +1251,7 @@ filter Set-GitHubRepository $ConfirmPreference = 'None' } - if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Update GitHub Repository')) + if (-not $PSCmdlet.ShouldProcess($RepositoryName, $shouldProcessMessage)) { return } From f26dca73ab868f43e47781fbed1bff0989591443 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 28 Jun 2020 13:00:07 +0100 Subject: [PATCH 03/13] Update GitHubLabels ShouldProcess --- GitHubLabels.ps1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 66cef12f..89560bfe 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -1089,8 +1089,7 @@ function Set-GitHubIssueLabel #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements', - ConfirmImpact='High')] + DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubLabelTypeName})] [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( @@ -1155,12 +1154,20 @@ function Set-GitHubIssueLabel 'labels' = $labelNames } + $shouldProcessMessage = "Set GitHub Issue Label(s) $($Label -join ', ')" + + if ([System.String]::IsNullOrEmpty($Label)) + { + $ConfirmPreference = 'Low' + $shouldProcessMessage = 'Remove all GitHub Issue Labels' + } + if ($Force -and (-not $Confirm)) { $ConfirmPreference = 'None' } - if (-not $PSCmdlet.ShouldProcess(($Label -join ', '), 'Set GitHub Issue Label')) + if (-not $PSCmdlet.ShouldProcess("Issue #$Issue", $shouldProcessMessage)) { return } From 87a0611c332c4c3dab2e2e8ec9bd37156567ca9c Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 28 Jun 2020 13:00:32 +0100 Subject: [PATCH 04/13] Fix GitHubAnalytics formatting --- GitHubAnalytics.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitHubAnalytics.ps1 b/GitHubAnalytics.ps1 index 4493aeeb..e0e2ba91 100644 --- a/GitHubAnalytics.ps1 +++ b/GitHubAnalytics.ps1 @@ -37,7 +37,7 @@ function Group-GitHubIssue $issues += Get-GitHubIssue -Uri 'https://github.com/powershell/xactivedirectory' $issues | Group-GitHubIssue -Weeks 12 -DateType Closed #> - [CmdletBinding(DefaultParameterSetName='Weekly')] + [CmdletBinding(DefaultParameterSetName = 'Weekly')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")] param ( From 29bafb3d3ac5ff8f95fc3712e597dff52b153fce Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Mon, 29 Jun 2020 17:33:04 +0100 Subject: [PATCH 05/13] Fix review comments --- GitHubConfiguration.ps1 | 6 +++--- GitHubIssueComments.ps1 | 2 +- GitHubProjectColumns.ps1 | 2 +- GitHubPullRequests.ps1 | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index d215b3a6..ee3d0d35 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -265,7 +265,7 @@ function Set-GitHubConfiguration } } - if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration',' Save')) + if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration','Save')) { return } @@ -367,7 +367,7 @@ function Save-GitHubConfiguration [string] $Path ) - if (-not $PSCmdlet.ShouldProcess('GitHub Configuration','Save')) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Save')) { return } @@ -539,7 +539,7 @@ function Reset-GitHubConfiguration Set-TelemetryEvent -EventName Reset-GitHubConfiguration - if (-not $PSCmdlet.ShouldProcess('GitHub Configuration','Reset')) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Reset')) { return } diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 4d19bf46..92f5c795 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -556,7 +556,7 @@ filter Set-GitHubIssueComment 'body' = $Body } - if (-not $PSCmdlet.ShouldProcess($Issue, 'Create GitHub Issue Comment')) + if (-not $PSCmdlet.ShouldProcess($Comment, 'Update GitHub Issue Comment')) { return } diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 210b48af..73025afb 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -477,7 +477,7 @@ filter Move-GitHubProjectColumn 'position' = $Position } - if (-not $PSCmdlet.ShouldProcess($ColumnName, 'Move GitHub Project Column')) + if (-not $PSCmdlet.ShouldProcess($Column, 'Move GitHub Project Column')) { return } diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index e0e5fc5e..fc73260c 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -395,6 +395,7 @@ filter New-GitHubPullRequest if ($PSBoundParameters.ContainsKey('Title')) { $description = "Creating pull request $Title in $RepositoryName" + $shouldProcessAction = "Create GitHub Pull Request $Title" $postBody['title'] = $Title # Body may be whitespace, although this might not be useful @@ -406,6 +407,7 @@ filter New-GitHubPullRequest else { $description = "Creating pull request for issue $Issue in $RepositoryName" + $shouldProcessAction = "Create GitHub Pull Request for Issue $Issue" $postBody['issue'] = $Issue } @@ -420,7 +422,7 @@ filter New-GitHubPullRequest $acceptHeader = 'application/vnd.github.shadow-cat-preview+json' } - if (-not $PSCmdlet.ShouldProcess($Title, 'Create GitHub Pull Request')) + if (-not $PSCmdlet.ShouldProcess($RepositoryName, $shouldProcessAction)) { return } From ebf097044c40b36aa3dd440e7f1e0f98bf0be5a8 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Mon, 6 Jul 2020 18:27:31 +0100 Subject: [PATCH 06/13] Fix review comments --- GitHubConfiguration.ps1 | 20 ++++++++++---------- GitHubPullRequests.ps1 | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index ee3d0d35..a09df731 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -265,7 +265,7 @@ function Set-GitHubConfiguration } } - if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration','Save')) + if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration', 'Save')) { return } @@ -537,13 +537,13 @@ function Reset-GitHubConfiguration [switch] $SessionOnly ) - Set-TelemetryEvent -EventName Reset-GitHubConfiguration - if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Reset')) { return } + Set-TelemetryEvent -EventName Reset-GitHubConfiguration + if (-not $SessionOnly) { $null = Remove-Item -Path $script:configurationFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev @@ -928,6 +928,11 @@ function Set-GitHubAuthentication [switch] $SessionOnly ) + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Set')) + { + return + } + if (-not $PSBoundParameters.ContainsKey('Credential')) { $message = 'Please provide your GitHub API Token in the Password field. You can enter anything in the username field (it will be ignored).' @@ -949,11 +954,6 @@ function Set-GitHubAuthentication $script:accessTokenCredential = $Credential - if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Set')) - { - return - } - Write-InvocationLog if (-not $SessionOnly) @@ -996,13 +996,13 @@ function Clear-GitHubAuthentication [switch] $SessionOnly ) - Set-TelemetryEvent -EventName Clear-GitHubAuthentication - if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Clear')) { return } + Set-TelemetryEvent -EventName Clear-GitHubAuthentication + Write-InvocationLog $script:accessTokenCredential = $null diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index fc73260c..ed4c3680 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -395,7 +395,7 @@ filter New-GitHubPullRequest if ($PSBoundParameters.ContainsKey('Title')) { $description = "Creating pull request $Title in $RepositoryName" - $shouldProcessAction = "Create GitHub Pull Request $Title" + $shouldProcessAction = "Create GitHub Pull Request: $Title" $postBody['title'] = $Title # Body may be whitespace, although this might not be useful From 66883c74bc3ed027920f92ca2d71593a1ba185bf Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 8 Jul 2020 17:45:28 +0100 Subject: [PATCH 07/13] Update review comments --- GitHubProjects.ps1 | 2 -- GitHubUsers.ps1 | 2 -- 2 files changed, 4 deletions(-) diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 90a884d1..33745133 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -347,8 +347,6 @@ filter New-GitHubProject [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $telemetryProperties['ProjectName'] = Get-PiiSafeString -PlainText $ProjectName diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 6e3678af..6d886857 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -369,8 +369,6 @@ function Set-GitHubProfile [switch] $NoStatus ) - Write-InvocationLog - $hashBody = @{} if ($PSBoundParameters.ContainsKey('Name')) { $hashBody['name'] = $Name } if ($PSBoundParameters.ContainsKey('Email')) { $hashBody['email'] = $Email } From fafb237f7be4e70e2d3dc3bf38b26ff3314d7a3b Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 21 Jul 2020 18:14:14 +0100 Subject: [PATCH 08/13] Remove ShouldProcess --- GitHubCore.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 37228a89..8de1fa73 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -653,11 +653,6 @@ function Invoke-GHRestMethodMultipleResult [switch] $NoStatus ) - if (-not $PSCmdlet.ShouldProcess($UriFragment, "Invoke-GHRestMethod")) - { - return - } - $AccessToken = Get-AccessToken -AccessToken $AccessToken $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() From 4bdd25cb7a6919f503e757a65addeec14b243a98 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 21 Jul 2020 20:58:06 +0100 Subject: [PATCH 09/13] Fix review comments --- GitHubAssignees.ps1 | 8 +++---- GitHubBranches.ps1 | 41 ++++++++++++++++---------------- GitHubConfiguration.ps1 | 8 +++---- GitHubContents.ps1 | 4 ++-- GitHubGistComments.ps1 | 8 +++---- GitHubGists.ps1 | 24 +++++++++---------- GitHubIssueComments.ps1 | 12 +++++----- GitHubIssues.ps1 | 16 ++++++------- GitHubLabels.ps1 | 22 ++++++++--------- GitHubMilestones.ps1 | 8 +++---- GitHubProjectCards.ps1 | 10 ++++---- GitHubProjectColumns.ps1 | 16 ++++++------- GitHubProjects.ps1 | 12 +++++----- GitHubPullRequests.ps1 | 4 ++-- GitHubReactions.ps1 | 39 +++++++++++++++++------------- GitHubReleases.ps1 | 2 +- GitHubRepositories.ps1 | 50 +++++++++++++++++++-------------------- GitHubRepositoryForks.ps1 | 4 ++-- GitHubUsers.ps1 | 4 ++-- 19 files changed, 146 insertions(+), 146 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 126a489d..79b33841 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -390,6 +390,8 @@ function Add-GitHubAssignee end { + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -422,8 +424,6 @@ function Add-GitHubAssignee return } - Write-InvocationLog - return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } } @@ -582,6 +582,8 @@ function Remove-GitHubAssignee end { + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -607,8 +609,6 @@ function Remove-GitHubAssignee return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/assignees" 'Body' = (ConvertTo-Json -InputObject $hashBody) diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 0657e7ed..aa378685 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -233,9 +233,6 @@ filter New-GitHubRepositoryBranch PositionalBinding = $false )] [OutputType({$script:GitHubBranchTypeName})] - [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.')] @@ -334,6 +331,11 @@ filter New-GitHubRepositoryBranch sha = $originBranch.commit.sha } + if (-not $PSCmdlet.ShouldProcess($BranchName, 'Create Repository Branch')) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -427,9 +429,6 @@ filter Remove-GitHubRepositoryBranch DefaultParameterSetName = 'Elements', PositionalBinding = $false, ConfirmImpact = 'High')] - [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.")] @@ -464,6 +463,8 @@ filter Remove-GitHubRepositoryBranch [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -480,23 +481,23 @@ filter Remove-GitHubRepositoryBranch $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($BranchName, "Remove Repository Branch")) + if (-not $PSCmdlet.ShouldProcess($BranchName, "Remove Repository Branch")) { - Write-InvocationLog - - $params = @{ - 'UriFragment' = $uriFragment - 'Method' = 'Delete' - 'Description' = "Deleting branch $BranchName from $RepositoryName" - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue ` - -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - Invoke-GHRestMethod @params | Out-Null + $params = @{ + 'UriFragment' = $uriFragment + 'Method' = 'Delete' + 'Description' = "Deleting branch $BranchName from $RepositoryName" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue ` + -Name NoStatus -ConfigValueName DefaultNoStatus) } + + Invoke-GHRestMethod @params | Out-Null } filter Add-GitHubBranchAdditionalProperties diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index a09df731..d264693e 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -928,6 +928,8 @@ function Set-GitHubAuthentication [switch] $SessionOnly ) + Write-InvocationLog + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Set')) { return @@ -954,8 +956,6 @@ function Set-GitHubAuthentication $script:accessTokenCredential = $Credential - Write-InvocationLog - if (-not $SessionOnly) { $null = New-Item -Path $script:accessTokenFilePath -Force @@ -996,6 +996,8 @@ function Clear-GitHubAuthentication [switch] $SessionOnly ) + Write-InvocationLog + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Clear')) { return @@ -1003,8 +1005,6 @@ function Clear-GitHubAuthentication Set-TelemetryEvent -EventName Clear-GitHubAuthentication - Write-InvocationLog - $script:accessTokenCredential = $null if (-not $SessionOnly) diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index c39bbbb3..6a28e2f4 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -358,6 +358,8 @@ filter Set-GitHubContent [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -DisableValidation $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -431,8 +433,6 @@ filter Set-GitHubContent return } - Write-InvocationLog - $params = @{ UriFragment = $uriFragment Description = "Writing content for $Path in the $BranchName branch of $RepositoryName" diff --git a/GitHubGistComments.ps1 b/GitHubGistComments.ps1 index b8d43b31..e2baa147 100644 --- a/GitHubGistComments.ps1 +++ b/GitHubGistComments.ps1 @@ -85,7 +85,7 @@ filter Get-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -204,7 +204,7 @@ filter Remove-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if ($Force -and (-not $Confirm)) { @@ -296,7 +296,7 @@ filter New-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $hashBody = @{ 'body' = $Body @@ -400,7 +400,7 @@ filter Set-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $hashBody = @{ 'body' = $Body diff --git a/GitHubGists.ps1 b/GitHubGists.ps1 index d357bc49..11140ba8 100644 --- a/GitHubGists.ps1 +++ b/GitHubGists.ps1 @@ -161,7 +161,7 @@ filter Get-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -497,7 +497,7 @@ filter Remove-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if ($Force -and (-not $Confirm)) { @@ -587,7 +587,7 @@ filter Copy-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if (-not $PSCmdlet.ShouldProcess($Gist, "Forking gist")) { @@ -679,7 +679,7 @@ filter Set-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name $PSBoundParameters.Remove('Star') @@ -753,7 +753,7 @@ filter Add-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if (-not $PSCmdlet.ShouldProcess($Gist, "Starring gist")) { @@ -834,7 +834,7 @@ filter Remove-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if (-not $PSCmdlet.ShouldProcess($Gist, "Unstarring gist")) { @@ -913,7 +913,7 @@ filter Test-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} $params = @{ @@ -1069,7 +1069,7 @@ filter New-GitHubGist end { - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -1218,7 +1218,7 @@ filter Set-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -1460,7 +1460,7 @@ function Set-GitHubGistFile end { - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name if ($PSCmdlet.ParameterSetName -eq 'Content') @@ -1580,7 +1580,7 @@ function Remove-GitHubGistFile end { - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name $params = @{ @@ -1674,7 +1674,7 @@ filter Rename-GitHubGistFile [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name $params = @{ diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 92f5c795..bb7fc994 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -393,6 +393,8 @@ filter New-GitHubIssueComment [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -412,8 +414,6 @@ filter New-GitHubIssueComment return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/comments" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -542,6 +542,8 @@ filter Set-GitHubIssueComment [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -561,8 +563,6 @@ filter Set-GitHubIssueComment return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -684,6 +684,8 @@ filter Remove-GitHubIssueComment [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -704,8 +706,6 @@ filter Remove-GitHubIssueComment return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" 'Method' = 'Delete' diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index fb25303d..33639e88 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -618,6 +618,8 @@ filter New-GitHubIssue [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -641,8 +643,6 @@ filter New-GitHubIssue return } - Write-InvocationLog - $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -798,6 +798,8 @@ filter Set-GitHubIssue [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -828,8 +830,6 @@ filter Set-GitHubIssue return } - Write-InvocationLog - $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -936,6 +936,8 @@ filter Lock-GitHubIssue [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -967,8 +969,6 @@ filter Lock-GitHubIssue return } - Write-InvocationLog - $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1070,6 +1070,8 @@ filter Unlock-GitHubIssue [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1084,8 +1086,6 @@ filter Unlock-GitHubIssue return } - Write-InvocationLog - $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" 'Method' = 'Delete' diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 89560bfe..fa000f87 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -299,6 +299,8 @@ filter New-GitHubLabel [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -326,8 +328,6 @@ filter New-GitHubLabel return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -460,6 +460,8 @@ filter Remove-GitHubLabel [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -479,8 +481,6 @@ filter Remove-GitHubLabel return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" 'Method' = 'Delete' @@ -610,6 +610,8 @@ filter Set-GitHubLabel [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -636,8 +638,6 @@ filter Set-GitHubLabel return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -754,6 +754,8 @@ filter Initialize-GitHubLabel [switch] $NoStatus ) + Write-InvocationLog + if (($null -eq $Label) -or ($Label.Count -eq 0)) { $Label = $script:defaultGitHubLabels @@ -781,8 +783,6 @@ filter Initialize-GitHubLabel return } - Write-InvocationLog - foreach ($labelToConfigure in $Label) { if ($labelToConfigure.name -notin $existingLabelNames) @@ -954,6 +954,8 @@ function Add-GitHubIssueLabel end { + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -973,8 +975,6 @@ function Add-GitHubIssueLabel return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1172,8 +1172,6 @@ function Set-GitHubIssueLabel return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index c983f45a..c42ea0c8 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -336,6 +336,8 @@ filter New-GitHubMilestone [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -379,8 +381,6 @@ filter New-GitHubMilestone return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -532,6 +532,8 @@ filter Set-GitHubMilestone [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -576,8 +578,6 @@ filter Set-GitHubMilestone return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone" 'Body' = (ConvertTo-Json -InputObject $hashBody) diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index 87b48146..d91ff88a 100644 --- a/GitHubProjectCards.ps1 +++ b/GitHubProjectCards.ps1 @@ -222,6 +222,8 @@ filter New-GitHubProjectCard [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column/cards" @@ -259,8 +261,6 @@ filter New-GitHubProjectCard return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -353,6 +353,8 @@ filter Set-GitHubProjectCard [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $uriFragment = "/projects/columns/cards/$Card" @@ -383,8 +385,6 @@ filter Set-GitHubProjectCard return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -615,8 +615,6 @@ filter Move-GitHubProjectCard return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index 73025afb..8c471368 100644 --- a/GitHubProjectColumns.ps1 +++ b/GitHubProjectColumns.ps1 @@ -168,6 +168,8 @@ filter New-GitHubProjectColumn [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $telemetryProperties['Project'] = Get-PiiSafeString -PlainText $Project @@ -183,8 +185,6 @@ filter New-GitHubProjectColumn return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -255,6 +255,8 @@ filter Set-GitHubProjectColumn [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column" @@ -269,8 +271,6 @@ filter Set-GitHubProjectColumn return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -348,6 +348,8 @@ filter Remove-GitHubProjectColumn [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column" @@ -363,8 +365,6 @@ filter Remove-GitHubProjectColumn return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Description' = $description @@ -449,6 +449,8 @@ filter Move-GitHubProjectColumn [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $uriFragment = "/projects/columns/$Column/moves" @@ -482,8 +484,6 @@ filter Move-GitHubProjectColumn return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 33745133..ee761fd5 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -347,6 +347,8 @@ filter New-GitHubProject [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $telemetryProperties['ProjectName'] = Get-PiiSafeString -PlainText $ProjectName @@ -393,8 +395,6 @@ filter New-GitHubProject return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -503,6 +503,8 @@ filter Set-GitHubProject [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $uriFragment = "projects/$Project" @@ -539,8 +541,6 @@ filter Set-GitHubProject return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -637,6 +637,8 @@ filter Remove-GitHubProject [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{} $uriFragment = "projects/$Project" @@ -652,8 +654,6 @@ filter Remove-GitHubProject return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Description' = $description diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index ed4c3680..aa57f53f 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -361,6 +361,8 @@ filter New-GitHubPullRequest [switch] $NoStatus ) + Write-InvocationLog + if (-not [string]::IsNullOrWhiteSpace($HeadOwner)) { if ($Head.Contains(':')) @@ -427,8 +429,6 @@ filter New-GitHubPullRequest return } - Write-InvocationLog - $restParams = @{ 'UriFragment' = $uriFragment 'Method' = 'Post' diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 47c6e992..1c4e74d2 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -99,10 +99,7 @@ filter Get-GitHubReaction .NOTES Currently, issue comments, pull request comments and commit comments are not supported. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='ElementsIssue')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName='ElementsIssue')] [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( @@ -295,7 +292,6 @@ filter Set-GitHubReaction [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='ElementsIssue')] - [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( @@ -390,6 +386,13 @@ filter Set-GitHubReaction $description = "Setting reaction $ReactionType for $targetObjectTypeName $targetObjectNumber in $RepositoryName" + if (-not $PSCmdlet.ShouldProcess( + $ReactionId, + "Setting reaction for $targetObjectTypeName $targetObjectNumber in $RepositoryName")) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Description' = $description @@ -595,23 +598,25 @@ filter Remove-GitHubReaction $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess( + if (-not $PSCmdlet.ShouldProcess( $ReactionId, "Removing reaction for $targetObjectTypeName $targetObjectNumber in $RepositoryName")) { - $params = @{ - 'UriFragment' = $uriFragment - 'Description' = $description - 'Method' = 'Delete' - 'AcceptHeader' = $script:squirrelGirlAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'Method' = 'Delete' + 'AcceptHeader' = $script:squirrelGirlAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Add-GitHubReactionAdditionalProperties diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 3ec46e28..0faf57c9 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -174,7 +174,7 @@ filter Get-GitHubRelease [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index a10486ac..4278dc55 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -173,6 +173,8 @@ filter New-GitHubRepository [switch] $NoStatus ) + Write-InvocationLog + $telemetryProperties = @{ 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } @@ -217,8 +219,6 @@ filter New-GitHubRepository return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -392,8 +392,6 @@ filter New-GitHubRepositoryFromTemplate return } - Write-InvocationLog - $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -513,6 +511,8 @@ filter Remove-GitHubRepository [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -532,8 +532,6 @@ filter Remove-GitHubRepository return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName" 'Method' = 'Delete' @@ -735,7 +733,7 @@ filter Get-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog # We are explicitly disabling validation here because a valid parameter set for this function # allows the OwnerName to be passed in, but not the RepositoryName. That would allow the caller @@ -1213,6 +1211,8 @@ filter Set-GitHubRepository [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1256,8 +1256,6 @@ filter Set-GitHubRepository return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1355,7 +1353,7 @@ filter Get-GitHubRepositoryTopic [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1520,6 +1518,8 @@ function Set-GitHubRepositoryTopic end { + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1550,8 +1550,6 @@ function Set-GitHubRepositoryTopic return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/topics" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1674,7 +1672,7 @@ filter Get-GitHubRepositoryContributor [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1822,7 +1820,7 @@ filter Get-GitHubRepositoryCollaborator [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1933,7 +1931,7 @@ filter Get-GitHubRepositoryLanguage [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -2039,7 +2037,7 @@ filter Get-GitHubRepositoryTag [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -2158,6 +2156,8 @@ filter Move-GitHubRepositoryOwnership [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2180,8 +2180,6 @@ filter Move-GitHubRepositoryOwnership return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/transfer" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -2433,6 +2431,8 @@ filter Enable-GitHubRepositoryVulnerabilityAlert [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2447,8 +2447,6 @@ filter Enable-GitHubRepositoryVulnerabilityAlert return } - Write-InvocationLog - $params = @{ UriFragment = "repos/$OwnerName/$RepositoryName/vulnerability-alerts" Description = "Enabling Vulnerability Alerts for $RepositoryName" @@ -2552,6 +2550,8 @@ filter Disable-GitHubRepositoryVulnerabilityAlert [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2566,8 +2566,6 @@ filter Disable-GitHubRepositoryVulnerabilityAlert return } - Write-InvocationLog - $params = @{ UriFragment = "repos/$OwnerName/$RepositoryName/vulnerability-alerts" Description = "Disabling Vulnerability Alerts for $RepositoryName" @@ -2671,6 +2669,8 @@ filter Enable-GitHubRepositorySecurityFix [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2685,8 +2685,6 @@ filter Enable-GitHubRepositorySecurityFix return } - Write-InvocationLog - $params = @{ UriFragment = "repos/$OwnerName/$RepositoryName/automated-security-fixes" Description = "Enabling Automated Security Fixes for $RepositoryName" @@ -2789,6 +2787,8 @@ filter Disable-GitHubRepositorySecurityFix [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2803,8 +2803,6 @@ filter Disable-GitHubRepositorySecurityFix return } - Write-InvocationLog - $params = @{ UriFragment = "repos/$OwnerName/$RepositoryName/automated-security-fixes" Description = "Disabling Automated Security Fixes for $RepositoryName" diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 08939878..dbeaee70 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -209,6 +209,8 @@ filter New-GitHubRepositoryFork [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -231,8 +233,6 @@ filter New-GitHubRepositoryFork return } - Write-InvocationLog - $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/forks`?" + ($getParams -join '&') 'Method' = 'Post' diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 6d886857..b0e9163a 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -369,6 +369,8 @@ function Set-GitHubProfile [switch] $NoStatus ) + Write-InvocationLog + $hashBody = @{} if ($PSBoundParameters.ContainsKey('Name')) { $hashBody['name'] = $Name } if ($PSBoundParameters.ContainsKey('Email')) { $hashBody['email'] = $Email } @@ -383,8 +385,6 @@ function Set-GitHubProfile return } - Write-InvocationLog - $params = @{ 'UriFragment' = 'user' 'Method' = 'Patch' From 35fe9f65717a213c275ecb003b4406beae1c4d5a Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 21 Jul 2020 21:10:32 +0100 Subject: [PATCH 10/13] Fix `Set-TelemetryEvent` --- GitHubConfiguration.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index d264693e..c8477d1d 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -998,13 +998,13 @@ function Clear-GitHubAuthentication Write-InvocationLog + Set-TelemetryEvent -EventName Clear-GitHubAuthentication + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Clear')) { return } - Set-TelemetryEvent -EventName Clear-GitHubAuthentication - $script:accessTokenCredential = $null if (-not $SessionOnly) From be1d445da87c248dd2e998f7e63e796d2dbca3c7 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Fri, 31 Jul 2020 08:21:41 +0100 Subject: [PATCH 11/13] Fix review comments --- GitHubConfiguration.ps1 | 10 +++++----- Telemetry.ps1 | 5 ----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index c8477d1d..29902e83 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -249,6 +249,11 @@ function Set-GitHubConfiguration $persistedConfig = Read-GitHubConfiguration -Path $script:configurationFilePath } + if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration', 'Set')) + { + return + } + $properties = Get-Member -InputObject $script:configuration -MemberType NoteProperty | Select-Object -ExpandProperty Name foreach ($name in $properties) { @@ -265,11 +270,6 @@ function Set-GitHubConfiguration } } - if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration', 'Save')) - { - return - } - if (-not $SessionOnly) { Save-GitHubConfiguration -Configuration $persistedConfig -Path $script:configurationFilePath diff --git a/Telemetry.ps1 b/Telemetry.ps1 index e5595ead..3c9b94c5 100644 --- a/Telemetry.ps1 +++ b/Telemetry.ps1 @@ -154,11 +154,6 @@ function Invoke-SendTelemetryEvent $body = ConvertTo-Json -InputObject $TelemetryEvent -Depth $jsonConversionDepth -Compress $bodyAsBytes = [System.Text.Encoding]::UTF8.GetBytes($body) - if (-not $PSCmdlet.ShouldProcess($uri, "Invoke-WebRequest")) - { - return - } - try { Write-Log -Message "Sending telemetry event data to $uri [Timeout = $(Get-GitHubConfiguration -Name WebRequestTimeoutSec))]" -Level Verbose From 4dd1371175e44afdfc17f0d5f9de77fe2d243e6f Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 1 Aug 2020 15:26:16 +0100 Subject: [PATCH 12/13] Remove WhatIf/Confirm parms --- GitHubBranches.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 3c8d6177..3f21a1ca 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -285,8 +285,6 @@ filter New-GitHubRepositoryBranch OwnerName = $OwnerName RepositoryName = $RepositoryName BranchName = $BranchName - Whatif = $false - Confirm = $false } if ($PSBoundParameters.ContainsKey('AccessToken')) { From a6e205d2c7caec0c2ba04ea369f350cd74569fc4 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sat, 1 Aug 2020 15:32:58 +0100 Subject: [PATCH 13/13] Standardise ShouldProcess processing --- GitHubBranches.ps1 | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 3f21a1ca..fc493d27 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -961,27 +961,29 @@ filter New-GitHubRepositoryBranchProtectionRule $hashBody['allow_deletions'] = $AllowDeletions.ToBool() } - if ($PSCmdlet.ShouldProcess( + if (-not $PSCmdlet.ShouldProcess( "'$BranchName' branch of repository '$RepositoryName'", 'Create GitHub Repository Branch Protection Rule')) { - $jsonConversionDepth = 3 - - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" - Body = (ConvertTo-Json -InputObject $hashBody -Depth $jsonConversionDepth) - Description = "Setting $BranchName branch protection status for $RepositoryName" - Method = 'Put' - AcceptHeader = $script:lukeCageAcceptHeader - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` - -ConfigValueName DefaultNoStatus) - } + return + } - return (Invoke-GHRestMethod @params | Add-GitHubBranchProtectionRuleAdditionalProperties) + $jsonConversionDepth = 3 + + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" + Body = (ConvertTo-Json -InputObject $hashBody -Depth $jsonConversionDepth) + Description = "Setting $BranchName branch protection status for $RepositoryName" + Method = 'Put' + AcceptHeader = $script:lukeCageAcceptHeader + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` + -ConfigValueName DefaultNoStatus) } + + return (Invoke-GHRestMethod @params | Add-GitHubBranchProtectionRuleAdditionalProperties) } filter Remove-GitHubRepositoryBranchProtectionRule @@ -1096,23 +1098,25 @@ filter Remove-GitHubRepositoryBranchProtectionRule $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess("'$BranchName' branch of repository '$RepositoryName'", + if (-not $PSCmdlet.ShouldProcess("'$BranchName' branch of repository '$RepositoryName'", 'Remove GitHub Repository Branch Protection Rule')) { - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" - Description = "Removing $BranchName branch protection rule for $RepositoryName" - Method = 'Delete' - AcceptHeader = $script:lukeCageAcceptHeader - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` - -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params | Out-Null + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" + Description = "Removing $BranchName branch protection rule for $RepositoryName" + Method = 'Delete' + AcceptHeader = $script:lukeCageAcceptHeader + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` + -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params | Out-Null } filter Add-GitHubBranchAdditionalProperties