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 2c439da1..25a35aca 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -62,11 +62,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')] @@ -184,11 +181,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')] @@ -341,7 +335,6 @@ function New-GitHubAssignee 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.")] [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')] @@ -390,8 +383,6 @@ function New-GitHubAssignee end { - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -419,6 +410,13 @@ function New-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) } } @@ -575,8 +573,6 @@ function Remove-GitHubAssignee end { - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -597,21 +593,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 f595ace7..71a52f99 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -94,11 +94,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 0320f399..e6be119c 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 @@ -179,7 +178,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, @@ -246,6 +244,11 @@ function Set-GitHubConfiguration } } + if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration',' Save')) + { + return + } + if (-not $SessionOnly) { Save-GitHubConfiguration -Configuration $persistedConfig -Path $script:configurationFilePath @@ -332,8 +335,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, @@ -342,6 +344,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 @@ -507,12 +514,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*')) { @@ -555,8 +564,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 ) @@ -609,8 +617,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 ) @@ -692,13 +699,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 @@ -734,7 +745,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 } @@ -742,6 +752,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 @@ -787,8 +802,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), @@ -880,7 +894,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, @@ -888,8 +901,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).' @@ -910,15 +921,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 } } @@ -953,28 +969,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] } } @@ -1006,9 +1021,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 @@ -1085,8 +1099,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 7ce6472a..04933ecf 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -103,12 +103,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, @@ -425,94 +422,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 09068429..321be48c 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -106,7 +106,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, @@ -195,11 +195,6 @@ function Invoke-GHRestMethod $headers.Add("Content-Type", "application/json; charset=UTF-8") } - if (-not $PSCmdlet.ShouldProcess($url, "Invoke-WebRequest")) - { - return - } - $NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus $originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol @@ -643,8 +638,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)] - [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("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( @@ -884,8 +878,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 c904bc6a..530cd5b7 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -69,11 +69,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 1eacf806..ab1613c9 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -118,12 +118,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, @@ -360,7 +357,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')] @@ -393,8 +389,6 @@ filter New-GitHubIssueComment [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -409,6 +403,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) @@ -503,7 +504,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')] @@ -536,8 +536,6 @@ filter Set-GitHubIssueComment [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -552,6 +550,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) @@ -671,8 +676,6 @@ filter Remove-GitHubIssueComment [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -688,20 +691,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 46931a43..2636f465 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -145,11 +145,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, @@ -440,11 +437,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')] @@ -582,7 +576,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, @@ -619,8 +612,6 @@ filter New-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -639,6 +630,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) @@ -750,7 +748,6 @@ filter Update-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, @@ -792,8 +789,6 @@ filter Update-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -819,6 +814,13 @@ filter Update-GitHubIssue } } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Update GitHub Issue')) + { + return + } + + Write-InvocationLog + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -895,7 +897,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, @@ -924,8 +925,6 @@ filter Lock-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -952,6 +951,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) @@ -1025,7 +1031,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')] @@ -1052,8 +1057,6 @@ filter Unlock-GitHubIssue [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1063,6 +1066,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 41d306f5..38dc4809 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -85,11 +85,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, @@ -265,7 +262,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')] @@ -299,8 +295,6 @@ filter New-GitHubLabel [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -323,6 +317,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) @@ -453,8 +454,6 @@ filter Remove-GitHubLabel [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -469,21 +468,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 Update-GitHubLabel @@ -564,7 +567,6 @@ filter Update-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.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -599,8 +601,6 @@ filter Update-GitHubLabel [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -622,6 +622,13 @@ filter Update-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) @@ -713,7 +720,6 @@ filter Set-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')] @@ -759,17 +765,39 @@ filter Set-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 = Update-GitHubLabel -Label $labelToConfigure.name -NewName $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $updateGitHubLabelParms = @{ + Label = $labelToConfigure.name + NewName = $labelToConfigure.name + Color = $labelToConfigure.color + Confirm = $false + WhatIf = $false + } + + $null = Update-GitHubLabel @updateGitHubLabelParms @commonParams } } @@ -778,7 +806,13 @@ filter Set-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 } } } @@ -854,7 +888,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( @@ -908,8 +941,6 @@ function Add-GitHubIssueLabel end { - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -924,6 +955,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) @@ -1039,7 +1077,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')] @@ -1108,11 +1145,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) @@ -1270,21 +1309,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 ddbbd165..e6bafcdd 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -81,10 +81,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, @@ -295,7 +292,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, @@ -336,8 +332,6 @@ filter New-GitHubMilestone [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -376,6 +370,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) @@ -476,7 +477,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, @@ -526,8 +526,6 @@ filter Set-GitHubMilestone [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -567,6 +565,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) @@ -709,20 +714,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 a2498de5..f3f70f64 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, @@ -516,9 +510,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, @@ -647,9 +640,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 3476f263..a8de11bb 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -98,11 +98,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, @@ -305,7 +302,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, @@ -390,6 +386,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) @@ -474,7 +477,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, @@ -498,8 +500,6 @@ filter Set-GitHubProject [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "projects/$Project" @@ -531,6 +531,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 @@ -626,8 +633,6 @@ filter Remove-GitHubProject [switch] $NoStatus ) - Write-InvocationLog - $telemetryProperties = @{} $uriFragment = "projects/$Project" @@ -638,22 +643,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 09860e02..39d2e53d 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -88,10 +88,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, @@ -296,7 +293,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')] @@ -361,8 +357,6 @@ filter New-GitHubPullRequest [switch] $NoStatus ) - Write-InvocationLog - if (-not [string]::IsNullOrWhiteSpace($HeadOwner)) { if ($Head.Contains(':')) @@ -422,6 +416,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/GitHubReleases.ps1 b/GitHubReleases.ps1 index 997faff6..38442452 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -105,11 +105,8 @@ filter Get-GitHubRelease Information about published releases are available to everyone. Only users with push access will receive listings for draft releases. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubReleaseTypeName})] - [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')] [Parameter(ParameterSetName="Elements-ReleaseId")] diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index f5c0d8f4..a6180335 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -126,7 +126,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, @@ -173,8 +172,6 @@ filter New-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $telemetryProperties = @{ 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } @@ -214,6 +211,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) @@ -317,9 +321,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, @@ -382,6 +383,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) @@ -499,8 +509,6 @@ filter Remove-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -515,20 +523,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 @@ -654,11 +666,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( [Parameter( @@ -974,7 +983,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, @@ -1135,7 +1143,6 @@ filter Update-GitHubRepository DefaultParameterSetName='Elements', 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(ParameterSetName='Elements')] [string] $OwnerName, @@ -1186,8 +1193,6 @@ filter Update-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1197,11 +1202,6 @@ filter Update-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($Force -and (-not $Confirm)) - { - $ConfirmPreference = 'None' - } - $hashBody = @{} if ($PSBoundParameters.ContainsKey('NewName')) @@ -1229,6 +1229,18 @@ filter Update-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) @@ -1302,11 +1314,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')] @@ -1431,7 +1440,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')] @@ -1491,8 +1499,6 @@ function Set-GitHubRepositoryTopic end { - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -1516,6 +1522,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) @@ -1605,12 +1620,9 @@ filter Get-GitHubRepositoryContributor .EXAMPLE Get-GitHubRepositoryContributor -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -IncludeStatistics #> - [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')] @@ -1752,11 +1764,8 @@ filter Get-GitHubRepositoryCollaborator .EXAMPLE Get-GitHubRepositoryCollaborator -Uri 'https://github.com/PowerShell/PowerShellForGitHub' #> - [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')] @@ -1867,11 +1876,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')] @@ -1974,11 +1980,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')] @@ -2090,7 +2093,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')] @@ -2117,8 +2119,6 @@ filter Move-GitHubRepositoryOwnership [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2134,6 +2134,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) @@ -2394,24 +2403,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 @@ -2511,24 +2522,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 @@ -2628,24 +2641,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 @@ -2744,24 +2759,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 98e311d2..e3c2a415 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -61,11 +61,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')] @@ -187,7 +184,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, @@ -209,8 +205,6 @@ filter New-GitHubRepositoryFork [switch] $NoStatus ) - Write-InvocationLog - $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -228,6 +222,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 d3c26ddd..cd288170 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -67,11 +67,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')] @@ -181,11 +178,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')] @@ -301,11 +295,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')] @@ -425,11 +416,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 54b1f809..978645d0 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -70,11 +70,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 ( @@ -209,11 +206,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 1ed37ccc..333df5ea 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( @@ -354,7 +348,6 @@ function Update-GitHubCurrentUser #> [CmdletBinding(SupportsShouldProcess)] [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( [string] $Name, @@ -386,6 +379,13 @@ function Update-GitHubCurrentUser 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 17fa80e2..10ddc79c 100644 --- a/Helpers.ps1 +++ b/Helpers.ps1 @@ -259,8 +259,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( @@ -384,7 +383,7 @@ function Write-Log } else { - $logFileMessage | Out-File -FilePath $Path -Append + $logFileMessage | Out-File -FilePath $Path -Append -WhatIf:$false -Confirm:$false } } } @@ -458,7 +457,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 16efb7c5..ca789006 100644 --- a/Telemetry.ps1 +++ b/Telemetry.ps1 @@ -144,7 +144,7 @@ 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)] @@ -170,80 +170,74 @@ function Invoke-SendTelemetryEvent if ($NoStatus) { - if ($PSCmdlet.ShouldProcess($url, "Invoke-WebRequest")) - { - $params = @{} - $params.Add("Uri", $uri) - $params.Add("Method", $method) - $params.Add("Headers", $headers) - $params.Add("UseDefaultCredentials", $true) - $params.Add("UseBasicParsing", $true) - $params.Add("TimeoutSec", (Get-GitHubConfiguration -Name WebRequestTimeoutSec)) - $params.Add("Body", $bodyAsBytes) - - # Disable Progress Bar in function scope during Invoke-WebRequest - $ProgressPreference = 'SilentlyContinue' - - $result = Invoke-WebRequest @params - } + $params = @{} + $params.Add("Uri", $uri) + $params.Add("Method", $method) + $params.Add("Headers", $headers) + $params.Add("UseDefaultCredentials", $true) + $params.Add("UseBasicParsing", $true) + $params.Add("TimeoutSec", (Get-GitHubConfiguration -Name WebRequestTimeoutSec)) + $params.Add("Body", $bodyAsBytes) + + # Disable Progress Bar in function scope during Invoke-WebRequest + $ProgressPreference = 'SilentlyContinue' + + $result = Invoke-WebRequest @params } else { $jobName = "Invoke-SendTelemetryEvent-" + (Get-Date).ToFileTime().ToString() - if ($PSCmdlet.ShouldProcess($jobName, "Start-Job")) - { - [scriptblock]$scriptBlock = { - param($Uri, $Method, $Headers, $BodyAsBytes, $TimeoutSec, $ScriptRootPath) - - # We need to "dot invoke" Helpers.ps1 and GitHubConfiguration.ps1 within - # the context of this script block since we're running in a different - # PowerShell process and need access to Get-HttpWebResponseContent and - # config values referenced within Write-Log. - . (Join-Path -Path $ScriptRootPath -ChildPath 'Helpers.ps1') - . (Join-Path -Path $ScriptRootPath -ChildPath 'GitHubConfiguration.ps1') - - $params = @{} - $params.Add("Uri", $Uri) - $params.Add("Method", $Method) - $params.Add("Headers", $Headers) - $params.Add("UseDefaultCredentials", $true) - $params.Add("UseBasicParsing", $true) - $params.Add("TimeoutSec", $TimeoutSec) - $params.Add("Body", $BodyAsBytes) + [scriptblock]$scriptBlock = { + param($Uri, $Method, $Headers, $BodyAsBytes, $TimeoutSec, $ScriptRootPath) + + # We need to "dot invoke" Helpers.ps1 and GitHubConfiguration.ps1 within + # the context of this script block since we're running in a different + # PowerShell process and need access to Get-HttpWebResponseContent and + # config values referenced within Write-Log. + . (Join-Path -Path $ScriptRootPath -ChildPath 'Helpers.ps1') + . (Join-Path -Path $ScriptRootPath -ChildPath 'GitHubConfiguration.ps1') + + $params = @{} + $params.Add("Uri", $Uri) + $params.Add("Method", $Method) + $params.Add("Headers", $Headers) + $params.Add("UseDefaultCredentials", $true) + $params.Add("UseBasicParsing", $true) + $params.Add("TimeoutSec", $TimeoutSec) + $params.Add("Body", $BodyAsBytes) + + try + { + # Disable Progress Bar in function scope during Invoke-WebRequest + $ProgressPreference = 'SilentlyContinue' + Invoke-WebRequest @params + } + catch [System.Net.WebException] + { + # We need to access certain headers in the exception handling, + # but the actual *values* of the headers of a WebException don't get serialized + # when the RemoteException wraps it. To work around that, we'll extract the + # information that we actually care about *now*, and then we'll throw our own exception + # that is just a JSON object with the data that we'll later extract for processing in + # the main catch. + $ex = @{} + $ex.Message = $_.Exception.Message + $ex.StatusCode = $_.Exception.Response.StatusCode + $ex.StatusDescription = $_.Exception.Response.StatusDescription + $ex.InnerMessage = $_.ErrorDetails.Message try { - # Disable Progress Bar in function scope during Invoke-WebRequest - $ProgressPreference = 'SilentlyContinue' - - Invoke-WebRequest @params + $ex.RawContent = Get-HttpWebResponseContent -WebResponse $_.Exception.Response } - catch [System.Net.WebException] + catch { - # We need to access certain headers in the exception handling, - # but the actual *values* of the headers of a WebException don't get serialized - # when the RemoteException wraps it. To work around that, we'll extract the - # information that we actually care about *now*, and then we'll throw our own exception - # that is just a JSON object with the data that we'll later extract for processing in - # the main catch. - $ex = @{} - $ex.Message = $_.Exception.Message - $ex.StatusCode = $_.Exception.Response.StatusCode - $ex.StatusDescription = $_.Exception.Response.StatusDescription - $ex.InnerMessage = $_.ErrorDetails.Message - try - { - $ex.RawContent = Get-HttpWebResponseContent -WebResponse $_.Exception.Response - } - catch - { - Write-Log -Message "Unable to retrieve the raw HTTP Web Response:" -Exception $_ -Level Warning - } - - $jsonConversionDepth = 20 # Seems like it should be more than sufficient - throw (ConvertTo-Json -InputObject $ex -Depth $jsonConversionDepth) + Write-Log -Message "Unable to retrieve the raw HTTP Web Response:" -Exception $_ -Level Warning } + + $jsonConversionDepth = 20 # Seems like it should be more than sufficient + throw (ConvertTo-Json -InputObject $ex -Depth $jsonConversionDepth) } $null = Start-Job -Name $jobName -ScriptBlock $scriptBlock -Arg @( @@ -254,16 +248,10 @@ function Invoke-SendTelemetryEvent (Get-GitHubConfiguration -Name WebRequestTimeoutSec), $PSScriptRoot) - if ($PSCmdlet.ShouldProcess($jobName, "Wait-JobWithAnimation")) - { - $description = 'Sending telemetry data' - Wait-JobWithAnimation -Name $jobName -Description $Description - } + $description = 'Sending telemetry data' + Wait-JobWithAnimation -Name $jobName -Description $Description - if ($PSCmdlet.ShouldProcess($jobName, "Receive-Job")) - { - $result = Receive-Job $jobName -AutoRemoveJob -Wait -ErrorAction SilentlyContinue -ErrorVariable remoteErrors - } + $result = Receive-Job $jobName -AutoRemoveJob -Wait -ErrorAction SilentlyContinue -ErrorVariable remoteErrors } if ($remoteErrors.Count -gt 0) @@ -433,8 +421,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, @@ -546,8 +535,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,