diff --git a/GitHubAnalytics.ps1 b/GitHubAnalytics.ps1 index 0ee2310b..e0e2ba91 100644 --- a/GitHubAnalytics.ps1 +++ b/GitHubAnalytics.ps1 @@ -37,10 +37,7 @@ function Group-GitHubIssue $issues += Get-GitHubIssue -Uri 'https://github.com/powershell/xactivedirectory' $issues | Group-GitHubIssue -Weeks 12 -DateType Closed #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Weekly')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName = 'Weekly')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")] param ( @@ -165,10 +162,7 @@ function Group-GitHubPullRequest $pullRequests += Get-GitHubPullRequest -Uri 'https://github.com/powershell/xactivedirectory' $pullRequests | Group-GitHubPullRequest -Weeks 12 -DateType Closed #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Weekly')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName='Weekly')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")] param ( diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 3f3fbb06..79b33841 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -64,11 +64,8 @@ filter Get-GitHubAssignee Lists the available assignees for issues from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubUserTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -188,11 +185,8 @@ filter Test-GitHubAssignee Checks if a user has permission to be assigned to an issue from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType([bool])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -348,7 +342,6 @@ function Add-GitHubAssignee DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] [Alias('New-GitHubAssignee')] # Non-standard usage of the New verb, but done to avoid a breaking change post 0.14.0 - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -426,6 +419,11 @@ function Add-GitHubAssignee 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + if (-not $PSCmdlet.ShouldProcess($Issue, "Add Assignee(s) $($userNames -join ',')")) + { + return + } + return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } } @@ -606,21 +604,23 @@ 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 } + + $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 4491101f..fc493d27 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -97,11 +97,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( @@ -237,9 +234,6 @@ filter New-GitHubRepositoryBranch PositionalBinding = $false )] [OutputType({$script:GitHubBranchTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', - Justification = 'Methods called within here make use of PSShouldProcess, and the switch is - passed on to them inherently.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.')] @@ -291,8 +285,6 @@ filter New-GitHubRepositoryBranch OwnerName = $OwnerName RepositoryName = $RepositoryName BranchName = $BranchName - Whatif = $false - Confirm = $false } if ($PSBoundParameters.ContainsKey('AccessToken')) { @@ -338,6 +330,11 @@ filter New-GitHubRepositoryBranch sha = $originBranch.commit.sha } + if (-not $PSCmdlet.ShouldProcess($BranchName, 'Create Repository Branch')) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -431,9 +428,6 @@ filter Remove-GitHubRepositoryBranch DefaultParameterSetName = 'Elements', PositionalBinding = $false, ConfirmImpact = 'High')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", - Justification = "Methods called within here make use of PSShouldProcess, and the switch is - passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification = "One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] @@ -468,6 +462,8 @@ filter Remove-GitHubRepositoryBranch [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -484,23 +480,23 @@ filter Remove-GitHubRepositoryBranch $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($BranchName, "Remove Repository Branch")) + if (-not $PSCmdlet.ShouldProcess($BranchName, "Remove Repository Branch")) { - Write-InvocationLog - - $params = @{ - 'UriFragment' = $uriFragment - 'Method' = 'Delete' - 'Description' = "Deleting branch $BranchName from $RepositoryName" - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue ` - -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - Invoke-GHRestMethod @params | Out-Null + $params = @{ + 'UriFragment' = $uriFragment + 'Method' = 'Delete' + 'Description' = "Deleting branch $BranchName from $RepositoryName" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue ` + -Name NoStatus -ConfigValueName DefaultNoStatus) } + + Invoke-GHRestMethod @params | Out-Null } filter Get-GitHubRepositoryBranchProtectionRule @@ -965,27 +961,29 @@ filter New-GitHubRepositoryBranchProtectionRule $hashBody['allow_deletions'] = $AllowDeletions.ToBool() } - if ($PSCmdlet.ShouldProcess( + if (-not $PSCmdlet.ShouldProcess( "'$BranchName' branch of repository '$RepositoryName'", 'Create GitHub Repository Branch Protection Rule')) { - $jsonConversionDepth = 3 - - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" - Body = (ConvertTo-Json -InputObject $hashBody -Depth $jsonConversionDepth) - Description = "Setting $BranchName branch protection status for $RepositoryName" - Method = 'Put' - AcceptHeader = $script:lukeCageAcceptHeader - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` - -ConfigValueName DefaultNoStatus) - } + return + } + + $jsonConversionDepth = 3 - return (Invoke-GHRestMethod @params | Add-GitHubBranchProtectionRuleAdditionalProperties) + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" + Body = (ConvertTo-Json -InputObject $hashBody -Depth $jsonConversionDepth) + Description = "Setting $BranchName branch protection status for $RepositoryName" + Method = 'Put' + AcceptHeader = $script:lukeCageAcceptHeader + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` + -ConfigValueName DefaultNoStatus) } + + return (Invoke-GHRestMethod @params | Add-GitHubBranchProtectionRuleAdditionalProperties) } filter Remove-GitHubRepositoryBranchProtectionRule @@ -1100,23 +1098,25 @@ filter Remove-GitHubRepositoryBranchProtectionRule $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess("'$BranchName' branch of repository '$RepositoryName'", + if (-not $PSCmdlet.ShouldProcess("'$BranchName' branch of repository '$RepositoryName'", 'Remove GitHub Repository Branch Protection Rule')) { - $params = @{ - UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" - Description = "Removing $BranchName branch protection rule for $RepositoryName" - Method = 'Delete' - AcceptHeader = $script:lukeCageAcceptHeader - AccessToken = $AccessToken - TelemetryEventName = $MyInvocation.MyCommand.Name - TelemetryProperties = $telemetryProperties - NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` - -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params | Out-Null + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/branches/$BranchName/protection" + Description = "Removing $BranchName branch protection rule for $RepositoryName" + Method = 'Delete' + AcceptHeader = $script:lukeCageAcceptHeader + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus ` + -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params | Out-Null } filter Add-GitHubBranchAdditionalProperties diff --git a/GitHubConfiguration.ps1 b/GitHubConfiguration.ps1 index 17ceacec..29902e83 100644 --- a/GitHubConfiguration.ps1 +++ b/GitHubConfiguration.ps1 @@ -41,8 +41,7 @@ function Initialize-GitHubConfiguration .NOTES Internal helper method. This is actually invoked at the END of this file. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param() $script:seenTokenWarningThisSession = $false @@ -196,7 +195,6 @@ function Set-GitHubConfiguration [CmdletBinding( PositionalBinding = $false, SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [ValidatePattern('^(?!https?:)(?!api\.)(?!www\.).*')] [string] $ApiHostName, @@ -251,6 +249,11 @@ function Set-GitHubConfiguration $persistedConfig = Read-GitHubConfiguration -Path $script:configurationFilePath } + if (-not $PSCmdlet.ShouldProcess('GitHubConfiguration', 'Set')) + { + return + } + $properties = Get-Member -InputObject $script:configuration -MemberType NoteProperty | Select-Object -ExpandProperty Name foreach ($name in $properties) { @@ -355,8 +358,7 @@ function Save-GitHubConfiguration Serializes $config as a JSON object to 'c:\foo\config.json' #> - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)] [PSCustomObject] $Configuration, @@ -365,6 +367,11 @@ function Save-GitHubConfiguration [string] $Path ) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Save')) + { + return + } + $null = New-Item -Path $Path -Force ConvertTo-Json -InputObject $Configuration | Set-Content -Path $Path -Force -ErrorAction SilentlyContinue -ErrorVariable ev @@ -530,14 +537,16 @@ function Reset-GitHubConfiguration [switch] $SessionOnly ) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Reset')) + { + return + } + Set-TelemetryEvent -EventName Reset-GitHubConfiguration if (-not $SessionOnly) { - if ($PSCmdlet.ShouldProcess($script:configurationFilePath, "Delete configuration file")) - { - $null = Remove-Item -Path $script:configurationFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev - } + $null = Remove-Item -Path $script:configurationFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev if (($null -ne $ev) -and ($ev.Count -gt 0) -and ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) { @@ -580,8 +589,7 @@ function Read-GitHubConfiguration Returns back an object with the deserialized object contained in the specified file, if it exists and is valid. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param( [string] $Path ) @@ -634,8 +642,7 @@ function Import-GitHubConfiguration within a deserialized object from the content in $Path. The configuration object is then returned. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param( [string] $Path ) @@ -719,13 +726,17 @@ function Backup-GitHubConfiguration Writes the user's current configuration file to c:\foo\config.json. #> [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [string] $Path, [switch] $Force ) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Backup')) + { + return + } + # Make sure that the path that we're going to be storing the file exists. $null = New-Item -Path (Split-Path -Path $Path -Parent) -ItemType Directory -Force @@ -761,7 +772,6 @@ function Restore-GitHubConfiguration Makes the contents of c:\foo\config.json be the user's configuration for the module. #> [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [ValidateScript({ if (Test-Path -Path $_ -PathType Leaf) { $true } @@ -769,6 +779,11 @@ function Restore-GitHubConfiguration [string] $Path ) + if (-not $PSCmdlet.ShouldProcess('GitHub Configuration', 'Restore')) + { + return + } + # Make sure that the path that we're going to be storing the file exists. $null = New-Item -Path (Split-Path -Path $script:configurationFilePath -Parent) -ItemType Directory -Force @@ -814,8 +829,7 @@ function Resolve-ParameterWithDefaultConfigurationValue Checks to see if the NoStatus switch was provided by the user from the calling method. If so, uses that value. otherwise uses the DefaultNoStatus value currently configured. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] param( $BoundParameters = (Get-Variable -Name PSBoundParameters -Scope 1 -ValueOnly), @@ -907,7 +921,6 @@ function Set-GitHubAuthentication authentication, but keeps it in memory only for the duration of this PowerShell session.. #> [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUsePSCredentialType", "", Justification="The System.Management.Automation.Credential() attribute does not appear to work in PowerShell v4 which we need to support.")] param( [PSCredential] $Credential, @@ -917,6 +930,11 @@ function Set-GitHubAuthentication Write-InvocationLog + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Set')) + { + return + } + if (-not $PSBoundParameters.ContainsKey('Credential')) { $message = 'Please provide your GitHub API Token in the Password field. You can enter anything in the username field (it will be ignored).' @@ -937,15 +955,13 @@ function Set-GitHubAuthentication } $script:accessTokenCredential = $Credential + 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 } } @@ -984,24 +1000,23 @@ function Clear-GitHubAuthentication Set-TelemetryEvent -EventName Clear-GitHubAuthentication - if ($PSCmdlet.ShouldProcess("Clear memory cache")) + if (-not $PSCmdlet.ShouldProcess('GitHub Authentication', 'Clear')) { - $script:accessTokenCredential = $null + return } + $script:accessTokenCredential = $null + if (-not $SessionOnly) { - if ($PSCmdlet.ShouldProcess("Clear file-based cache")) - { - Remove-Item -Path $script:accessTokenFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev + Remove-Item -Path $script:accessTokenFilePath -Force -ErrorAction SilentlyContinue -ErrorVariable ev - if (($null -ne $ev) -and - ($ev.Count -gt 0) -and - ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) - { - $message = "Experienced a problem trying to remove the file that persists the Access Token [$script:accessTokenFilePath]." - Write-Log -Message $message -Level Warning -Exception $ev[0] - } + if (($null -ne $ev) -and + ($ev.Count -gt 0) -and + ($ev[0].FullyQualifiedErrorId -notlike 'PathNotFound*')) + { + $message = "Experienced a problem trying to remove the file that persists the Access Token [$script:accessTokenFilePath]." + Write-Log -Message $message -Level Warning -Exception $ev[0] } } @@ -1033,9 +1048,8 @@ function Get-AccessToken .OUTPUTS System.String #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Justification="For back-compat with v0.1.0, this still supports the deprecated method of using a global variable for storing the Access Token.")] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [OutputType([String])] param( [string] $AccessToken @@ -1112,8 +1126,7 @@ function Test-GitHubAuthenticationConfigured Returns $true if the session is authenticated; $false otherwise #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] [OutputType([Boolean])] param() diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 85b290f8..6a28e2f4 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -105,12 +105,9 @@ Unable to specify Path as ValueFromPipeline because a Repository object may be incorrectly coerced into a string used for Path, thus confusing things. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName = 'Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType([String])] [OutputType({$script:GitHubContentTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -361,6 +358,8 @@ filter Set-GitHubContent [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -DisableValidation $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -427,94 +426,94 @@ 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 + } + + $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 e20bb8a5..6f5437fb 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -119,7 +119,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, @@ -257,11 +257,6 @@ function Invoke-GHRestMethod $headers.Add("Content-Type", $ContentType) } - if (-not $PSCmdlet.ShouldProcess($url, "Invoke-WebRequest")) - { - return - } - $originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol # When $Save is in use, we need to remember what file we're saving the result to. @@ -634,7 +629,7 @@ function Invoke-GHRestMethodMultipleResult but the request happens in the foreground and there is no additional status shown to the user until a response is returned from the REST request. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] [OutputType([Object[]])] param( @@ -659,11 +654,6 @@ function Invoke-GHRestMethodMultipleResult [switch] $NoStatus ) - if (-not $PSCmdlet.ShouldProcess($UriFragment, "Invoke-GHRestMethod")) - { - return - } - $AccessToken = Get-AccessToken -AccessToken $AccessToken $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() @@ -919,8 +909,7 @@ function Resolve-RepositoryElements .OUTPUTS [PSCustomObject] - The OwnerName and RepositoryName elements to be used #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="This was the most accurate name that I could come up with. Internal only anyway.")] param ( diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 2dc597db..05764137 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -71,11 +71,8 @@ filter Get-GitHubEvent Get the events for the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='RepositoryElements')] + [CmdletBinding(DefaultParameterSetName = 'RepositoryElements')] [OutputType({$script:GitHubEventTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, diff --git a/GitHubGistComments.ps1 b/GitHubGistComments.ps1 index b8d43b31..e2baa147 100644 --- a/GitHubGistComments.ps1 +++ b/GitHubGistComments.ps1 @@ -85,7 +85,7 @@ filter Get-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -204,7 +204,7 @@ filter Remove-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if ($Force -and (-not $Confirm)) { @@ -296,7 +296,7 @@ filter New-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $hashBody = @{ 'body' = $Body @@ -400,7 +400,7 @@ filter Set-GitHubGistComment [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $hashBody = @{ 'body' = $Body diff --git a/GitHubGists.ps1 b/GitHubGists.ps1 index d357bc49..11140ba8 100644 --- a/GitHubGists.ps1 +++ b/GitHubGists.ps1 @@ -161,7 +161,7 @@ filter Get-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -497,7 +497,7 @@ filter Remove-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if ($Force -and (-not $Confirm)) { @@ -587,7 +587,7 @@ filter Copy-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if (-not $PSCmdlet.ShouldProcess($Gist, "Forking gist")) { @@ -679,7 +679,7 @@ filter Set-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name $PSBoundParameters.Remove('Star') @@ -753,7 +753,7 @@ filter Add-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if (-not $PSCmdlet.ShouldProcess($Gist, "Starring gist")) { @@ -834,7 +834,7 @@ filter Remove-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog if (-not $PSCmdlet.ShouldProcess($Gist, "Unstarring gist")) { @@ -913,7 +913,7 @@ filter Test-GitHubGistStar [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} $params = @{ @@ -1069,7 +1069,7 @@ filter New-GitHubGist end { - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -1218,7 +1218,7 @@ filter Set-GitHubGist [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{} @@ -1460,7 +1460,7 @@ function Set-GitHubGistFile end { - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name if ($PSCmdlet.ParameterSetName -eq 'Content') @@ -1580,7 +1580,7 @@ function Remove-GitHubGistFile end { - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name $params = @{ @@ -1674,7 +1674,7 @@ filter Rename-GitHubGistFile [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog Set-TelemetryEvent -EventName $MyInvocation.MyCommand.Name $params = @{ diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 48ec9447..bb7fc994 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -120,12 +120,9 @@ filter Get-GitHubIssueComment passing it in via the pipeline. This shows some of the different types of objects you can pipe into this function. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='RepositoryElements')] + [CmdletBinding(DefaultParameterSetName = 'RepositoryElements')] [Alias('Get-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 [OutputType({$script:GitHubIssueCommentTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -364,7 +361,6 @@ filter New-GitHubIssueComment DefaultParameterSetName='Elements')] [Alias('New-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 [OutputType({$script:GitHubIssueCommentTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -413,6 +409,11 @@ filter New-GitHubIssueComment 'body' = $Body } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Create GitHub Issue Comment')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/comments" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -509,7 +510,6 @@ filter Set-GitHubIssueComment DefaultParameterSetName='Elements')] [Alias('Set-GitHubComment')] # Aliased to avoid a breaking change after v0.14.0 [OutputType({$script:GitHubIssueCommentTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -558,6 +558,11 @@ filter Set-GitHubIssueComment 'body' = $Body } + if (-not $PSCmdlet.ShouldProcess($Comment, 'Update GitHub Issue Comment')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -696,20 +701,22 @@ 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 + } - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/comments/$Comment" + 'Method' = 'Delete' + 'Description' = "Removing comment $Comment for $RepositoryName" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Add-GitHubIssueCommentAdditionalProperties diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index afd90bcf..33639e88 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -147,11 +147,8 @@ filter Get-GitHubIssue Gets every issue in the microsoft\PowerShellForGitHub repository that is assigned to Octocat. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubIssueTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -444,11 +441,8 @@ filter Get-GitHubIssueTimeline .EXAMPLE Get-GitHubIssueTimeline -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 24 #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubEventTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -588,7 +582,6 @@ filter New-GitHubIssue SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -645,6 +638,11 @@ 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 + } + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -759,7 +757,6 @@ filter Set-GitHubIssue DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] [Alias('Update-GitHubIssue')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -828,6 +825,11 @@ filter Set-GitHubIssue } } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Update GitHub Issue')) + { + return + } + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -906,7 +908,6 @@ filter Lock-GitHubIssue [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -963,6 +964,11 @@ filter Lock-GitHubIssue $hashBody['lock_reason'] = $reasonConverter[$Reason] } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Lock GitHub Issue')) + { + return + } + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1038,7 +1044,6 @@ filter Unlock-GitHubIssue [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -1076,6 +1081,11 @@ filter Unlock-GitHubIssue 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + if (-not $PSCmdlet.ShouldProcess($Issue, 'Unlock GitHub Issue')) + { + return + } + $params = @{ 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/lock" 'Method' = 'Delete' diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 22cf446f..fa000f87 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -87,11 +87,8 @@ filter Get-GitHubLabel input. For the time being, the ParameterSets have been simplified and the validation of parameter combinations is happening within the function itself. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='NameUri')] + [CmdletBinding(DefaultParameterSetName = 'NameUri')] [OutputType({$script:GitHubLabelTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -269,7 +266,6 @@ filter New-GitHubLabel SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubLabelTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -327,6 +323,11 @@ filter New-GitHubLabel 'description' = $Description } + if (-not $PSCmdlet.ShouldProcess($Label, 'Create GitHub Label')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -475,21 +476,23 @@ 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 + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" + 'Method' = 'Delete' + 'Description' = "Deleting label $Label from $RepositoryName" + 'AcceptHeader' = $script:symmetraAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Set-GitHubLabel @@ -573,7 +576,6 @@ filter Set-GitHubLabel DefaultParameterSetName='Elements')] [OutputType({$script:GitHubLabelTypeName})] [Alias('Update-GitHubLabel')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -631,6 +633,11 @@ filter Set-GitHubLabel if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } if ($PSBoundParameters.ContainsKey('Color')) { $hashBody['color'] = $Color } + if (-not $PSCmdlet.ShouldProcess($Label, 'Update GitHub Label')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/labels/$Label" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -724,7 +731,6 @@ filter Initialize-GitHubLabel [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -748,6 +754,8 @@ filter Initialize-GitHubLabel [switch] $NoStatus ) + Write-InvocationLog + if (($null -eq $Label) -or ($Label.Count -eq 0)) { $Label = $script:defaultGitHubLabels @@ -770,17 +778,37 @@ filter Initialize-GitHubLabel $existingLabels = Get-GitHubLabel @commonParams $existingLabelNames = $existingLabels.name + if (-not $PSCmdlet.ShouldProcess(($Label -join ', '), 'Set GitHub Label')) + { + return + } + foreach ($labelToConfigure in $Label) { if ($labelToConfigure.name -notin $existingLabelNames) { # Create label if it doesn't exist - $null = New-GitHubLabel -Label $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $newGitHubLabelParms = @{ + Label = $labelToConfigure.name + Color = $labelToConfigure.color + Confirm = $false + WhatIf = $false + } + + $null = New-GitHubLabel @newGitHubLabelParms @commonParams } else { # Update label's color if it already exists - $null = Set-GitHubLabel -Label $labelToConfigure.name -NewName $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $setGitHubLabelParms = @{ + Label = $labelToConfigure.name + NewName = $labelToConfigure.name + Color = $labelToConfigure.color + Confirm = $false + WhatIf = $false + } + + $null = Set-GitHubLabel @setGitHubLabelParms @commonParams } } @@ -789,7 +817,13 @@ filter Initialize-GitHubLabel if ($labelName -notin $labelNames) { # Remove label if it exists but is not in desired label list - $null = Remove-GitHubLabel -Label $labelName @commonParams -Confirm:$false + $removeGitHubLabelParms = @{ + Label = $labelName + Confirm = $false + WhatIf = $false + } + + $null = Remove-GitHubLabel @removeGitHubLabelParms @commonParams } } } @@ -867,7 +901,6 @@ function Add-GitHubIssueLabel SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubLabelTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( @@ -937,6 +970,11 @@ function Add-GitHubIssueLabel 'labels' = $labelNames } + if (-not $PSCmdlet.ShouldProcess(($Label -join ', '), 'Add GitHub Issue Label')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$Issue/labels" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1051,10 +1089,8 @@ function Set-GitHubIssueLabel #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements', - ConfirmImpact='High')] + 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')] @@ -1118,12 +1154,20 @@ function Set-GitHubIssueLabel 'labels' = $labelNames } + $shouldProcessMessage = "Set GitHub Issue Label(s) $($Label -join ', ')" + + if ([System.String]::IsNullOrEmpty($Label)) + { + $ConfirmPreference = 'Low' + $shouldProcessMessage = 'Remove all GitHub Issue Labels' + } + if ($Force -and (-not $Confirm)) { $ConfirmPreference = 'None' } - if (($labelNames.Count -eq 0) -and (-not $PSCmdlet.ShouldProcess($Issue, "Remove all labels from issue"))) + if (-not $PSCmdlet.ShouldProcess("Issue #$Issue", $shouldProcessMessage)) { return } @@ -1287,21 +1331,23 @@ filter Remove-GitHubIssueLabel $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Label, "Remove label")) + if (-not $PSCmdlet.ShouldProcess($Label, 'Remove GitHub Issue label')) { - $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Label" - 'Method' = 'Delete' - 'Description' = $description - 'AcceptHeader' = $script:symmetraAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/issues/$Issue/labels/$Label" + 'Method' = 'Delete' + 'Description' = $description + 'AcceptHeader' = $script:symmetraAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Add-GitHubLabelAdditionalProperties diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index 7326bf5e..c42ea0c8 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -83,10 +83,7 @@ filter Get-GitHubMilestone Get-GitHubMilestone -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -Milestone 1 Get milestone number 1 for the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='RepositoryElements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName = 'RepositoryElements')] param( [Parameter( Mandatory, @@ -299,7 +296,6 @@ filter New-GitHubMilestone [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -380,6 +376,11 @@ filter New-GitHubMilestone $hashBody.add('due_on', $dueOnFormattedTime) } + if (-not $PSCmdlet.ShouldProcess($Title, 'Create GitHub Milestone')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -482,7 +483,6 @@ filter Set-GitHubMilestone [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -573,6 +573,11 @@ filter Set-GitHubMilestone $hashBody.add('due_on', $dueOnFormattedTime) } + if (-not $PSCmdlet.ShouldProcess($Milestone, 'Set GitHub Milestone')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -717,20 +722,22 @@ filter Remove-GitHubMilestone $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess($Milestone, "Remove milestone")) + if (-not $PSCmdlet.ShouldProcess($Milestone, 'Remove GitHub Milestone')) { - $params = @{ - 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone" - 'Method' = 'Delete' - 'Description' = "Removing milestone $Milestone for $RepositoryName" - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone" + 'Method' = 'Delete' + 'Description' = "Removing milestone $Milestone for $RepositoryName" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Add-GitHubMilestoneAdditionalProperties diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index a90a0a41..07cda624 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -62,9 +62,8 @@ function Get-GitHubRateLimit .EXAMPLE Get-GitHubRateLimit #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubRateLimitTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [string] $AccessToken, @@ -135,9 +134,8 @@ function ConvertFrom-GitHubMarkdown Returns back '
Bolded Text
' #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType([String])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( @@ -276,12 +274,9 @@ filter Get-GitHubLicense [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result.content)) #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='All')] + [CmdletBinding(DefaultParameterSetName = 'All')] [OutputType({$script:GitHubLicenseTypeName})] [OutputType({$script:GitHubContentTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -410,9 +405,8 @@ function Get-GitHubEmoji .EXAMPLE Get-GitHubEmoji #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubEmojiTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [string] $AccessToken, @@ -517,9 +511,8 @@ filter Get-GitHubCodeOfConduct [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($result.content)) #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubCodeOfConductTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -648,9 +641,8 @@ filter Get-GitHubGitIgnore Returns the content of the VisualStudio.gitignore template. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubGitignoreTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( ValueFromPipeline, diff --git a/GitHubOrganizations.ps1 b/GitHubOrganizations.ps1 index 95e81e88..2a02a925 100644 --- a/GitHubOrganizations.ps1 +++ b/GitHubOrganizations.ps1 @@ -41,9 +41,8 @@ filter Get-GitHubOrganizationMember .EXAMPLE Get-GitHubOrganizationMember -OrganizationName PowerShell #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType({$script:GitHubUserTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param ( @@ -113,9 +112,8 @@ filter Test-GitHubOrganizationMember .EXAMPLE Test-GitHubOrganizationMember -OrganizationName PowerShell -UserName Octocat #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] [OutputType([bool])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param ( diff --git a/GitHubProjectCards.ps1 b/GitHubProjectCards.ps1 index ed911fa5..d91ff88a 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( @@ -260,6 +256,11 @@ filter New-GitHubProjectCard } } + if (-not $PSCmdlet.ShouldProcess($Column, 'Create GitHub Project Card')) + { + return + } + $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, @@ -380,6 +380,11 @@ filter Set-GitHubProjectCard $hashBody.add('archived', $false) } + if (-not $PSCmdlet.ShouldProcess($Card, 'Set GitHub Project Card')) + { + return + } + $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,11 @@ filter Move-GitHubProjectCard $hashBody.add('column_id', $Column) } + if (-not $PSCmdlet.ShouldProcess($Card, 'Move GitHub Project Card')) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription diff --git a/GitHubProjectColumns.ps1 b/GitHubProjectColumns.ps1 index f65cd309..8c471368 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( @@ -184,6 +180,11 @@ filter New-GitHubProjectColumn 'name' = $ColumnName } + if (-not $PSCmdlet.ShouldProcess($ColumnName, 'Create GitHub Project Column')) + { + return + } + $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( @@ -266,6 +266,11 @@ filter Set-GitHubProjectColumn 'name' = $ColumnName } + if (-not $PSCmdlet.ShouldProcess($ColumnName, 'Set GitHub Project Column')) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -355,21 +360,23 @@ 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 + $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( @@ -473,6 +479,11 @@ filter Move-GitHubProjectColumn 'position' = $Position } + if (-not $PSCmdlet.ShouldProcess($Column, 'Move GitHub Project Column')) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 87566375..ee761fd5 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -100,11 +100,8 @@ filter Get-GitHubProject Get a project by id, with this parameter you don't need any other information. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName = 'Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubPullRequestTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -309,7 +306,6 @@ filter New-GitHubProject SupportsShouldProcess, DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubPullRequestTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -394,6 +390,11 @@ filter New-GitHubProject $hashBody.add('body', $Description) } + if (-not $PSCmdlet.ShouldProcess($ProjectName, 'Create GitHub Project')) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -479,7 +480,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, @@ -536,6 +536,11 @@ filter Set-GitHubProject $apiDescription += ", organization_permission to '$OrganizationPermission'" } + if (-not $PSCmdlet.ShouldProcess($Project, 'Set GitHub Project')) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Description' = $apiDescription @@ -644,22 +649,23 @@ 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 + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'AccessToken' = $AccessToken + 'Method' = 'Delete' + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + 'AcceptHeader' = $script:inertiaAcceptHeader } + return Invoke-GHRestMethod @params } filter Add-GitHubProjectAdditionalProperties diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 50b87fea..aa57f53f 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -90,10 +90,7 @@ filter Get-GitHubPullRequest .EXAMPLE $pullRequests = Get-GitHubPullRequest -OwnerName microsoft -RepositoryName PowerShellForGitHub -State Closed #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName = 'Elements')] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -300,7 +297,6 @@ filter New-GitHubPullRequest New-GitHubPullRequest -Uri 'https://github.com/PowerShell/PSScriptAnalyzer' -Issue 642 -Head simple-test -HeadOwner octocat -Base development -Draft #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements_Title')] @@ -401,6 +397,7 @@ filter New-GitHubPullRequest if ($PSBoundParameters.ContainsKey('Title')) { $description = "Creating pull request $Title in $RepositoryName" + $shouldProcessAction = "Create GitHub Pull Request: $Title" $postBody['title'] = $Title # Body may be whitespace, although this might not be useful @@ -412,6 +409,7 @@ filter New-GitHubPullRequest else { $description = "Creating pull request for issue $Issue in $RepositoryName" + $shouldProcessAction = "Create GitHub Pull Request for Issue $Issue" $postBody['issue'] = $Issue } @@ -426,6 +424,11 @@ filter New-GitHubPullRequest $acceptHeader = 'application/vnd.github.shadow-cat-preview+json' } + if (-not $PSCmdlet.ShouldProcess($RepositoryName, $shouldProcessAction)) + { + return + } + $restParams = @{ 'UriFragment' = $uriFragment 'Method' = 'Post' diff --git a/GitHubReactions.ps1 b/GitHubReactions.ps1 index 47c6e992..1c4e74d2 100644 --- a/GitHubReactions.ps1 +++ b/GitHubReactions.ps1 @@ -99,10 +99,7 @@ filter Get-GitHubReaction .NOTES Currently, issue comments, pull request comments and commit comments are not supported. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='ElementsIssue')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding(DefaultParameterSetName='ElementsIssue')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( @@ -295,7 +292,6 @@ filter Set-GitHubReaction [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='ElementsIssue')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( @@ -390,6 +386,13 @@ filter Set-GitHubReaction $description = "Setting reaction $ReactionType for $targetObjectTypeName $targetObjectNumber in $RepositoryName" + if (-not $PSCmdlet.ShouldProcess( + $ReactionId, + "Setting reaction for $targetObjectTypeName $targetObjectNumber in $RepositoryName")) + { + return + } + $params = @{ 'UriFragment' = $uriFragment 'Description' = $description @@ -595,23 +598,25 @@ filter Remove-GitHubReaction $ConfirmPreference = 'None' } - if ($PSCmdlet.ShouldProcess( + if (-not $PSCmdlet.ShouldProcess( $ReactionId, "Removing reaction for $targetObjectTypeName $targetObjectNumber in $RepositoryName")) { - $params = @{ - 'UriFragment' = $uriFragment - 'Description' = $description - 'Method' = 'Delete' - 'AcceptHeader' = $script:squirrelGirlAcceptHeader - 'AccessToken' = $AccessToken - 'TelemetryEventName' = $MyInvocation.MyCommand.Name - 'TelemetryProperties' = $telemetryProperties - 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) - } + return + } - return Invoke-GHRestMethod @params + $params = @{ + 'UriFragment' = $uriFragment + 'Description' = $description + 'Method' = 'Delete' + 'AcceptHeader' = $script:squirrelGirlAcceptHeader + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Add-GitHubReactionAdditionalProperties diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 3ec46e28..0faf57c9 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -174,7 +174,7 @@ filter Get-GitHubRelease [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index e198ef29..4278dc55 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -127,7 +127,6 @@ filter New-GitHubRepository #> [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubRepositoryTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter( Mandatory, @@ -174,7 +173,7 @@ filter New-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $telemetryProperties = @{ 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) @@ -215,6 +214,11 @@ 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 + } + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -318,9 +322,6 @@ filter New-GitHubRepositoryFromTemplate SupportsShouldProcess, PositionalBinding = $false)] [OutputType({$script:GitHubRepositoryTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", - Justification="Methods called within here make use of PSShouldProcess, and the switch is - passed on to them inherently.")] param( [Parameter(ParameterSetName = 'Elements')] [string] $OwnerName, @@ -384,6 +385,13 @@ 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 + } + $params = @{ 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -503,7 +511,7 @@ filter Remove-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -519,20 +527,22 @@ 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 + $params = @{ + 'UriFragment' = "repos/$OwnerName/$RepositoryName" + 'Method' = 'Delete' + 'Description' = "Deleting $RepositoryName" + 'AccessToken' = $AccessToken + 'TelemetryEventName' = $MyInvocation.MyCommand.Name + 'TelemetryProperties' = $telemetryProperties + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } + + return Invoke-GHRestMethod @params } filter Get-GitHubRepository @@ -660,12 +670,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( @@ -727,7 +733,7 @@ filter Get-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog # We are explicitly disabling validation here because a valid parameter set for this function # allows the OwnerName to be passed in, but not the RepositoryName. That would allow the caller @@ -993,7 +999,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, @@ -1153,11 +1158,9 @@ filter Set-GitHubRepository #> [CmdletBinding( SupportsShouldProcess, - DefaultParameterSetName='Elements', - ConfirmImpact='High')] + DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryTypeName})] [Alias('Update-GitHubRepository')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -1208,7 +1211,7 @@ filter Set-GitHubRepository [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1219,22 +1222,14 @@ filter Set-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($Force -and (-not $Confirm)) - { - $ConfirmPreference = 'None' - } - $hashBody = @{} + $shouldProcessMessage = 'Update GitHub Repository' if ($PSBoundParameters.ContainsKey('NewName')) { - $existingName = if ($PSCmdlet.ParameterSetName -eq 'Uri') { $Uri } else { $OwnerName, $RepositoryName -join '/' } - if (-not $PSCmdlet.ShouldProcess($existingName, "Rename repository to '$NewName'")) - { - return - } - $hashBody['name'] = $NewName + $ConfirmPreference = 'Low' + $shouldProcessMessage = "Rename repository to '$NewName'" } if ($PSBoundParameters.ContainsKey('Description')) { $hashBody['description'] = $Description } @@ -1251,6 +1246,16 @@ filter Set-GitHubRepository if ($PSBoundParameters.ContainsKey('IsTemplate')) { $hashBody['is_template'] = $IsTemplate.ToBool() } if ($PSBoundParameters.ContainsKey('Archived')) { $hashBody['archived'] = $Archived.ToBool() } + if ($Force -and (-not $Confirm)) + { + $ConfirmPreference = 'None' + } + + if (-not $PSCmdlet.ShouldProcess($RepositoryName, $shouldProcessMessage)) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1326,11 +1331,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')] @@ -1351,7 +1353,7 @@ filter Get-GitHubRepositoryTopic [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1457,7 +1459,6 @@ function Set-GitHubRepositoryTopic SupportsShouldProcess, DefaultParameterSetName='ElementsName')] [OutputType({$script:GitHubRepositoryTopicTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='ElementsName')] [Parameter(ParameterSetName='ElementsClear')] @@ -1517,7 +1518,7 @@ function Set-GitHubRepositoryTopic end { - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1542,6 +1543,13 @@ function Set-GitHubRepositoryTopic 'names' = $topics } + if (-not $PSCmdlet.ShouldProcess( + $RepositoryName, + "Set GitHub Repository Topic $($Topic -join ', ')")) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/topics" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -1637,12 +1645,9 @@ filter Get-GitHubRepositoryContributor Gets a list of contributors for the PowerShellForGithub repository including statistics. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryContributorTypeName})] [OutputType({$script:GitHubRepositoryContributorStatisticsTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -1667,7 +1672,7 @@ filter Get-GitHubRepositoryContributor [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1790,11 +1795,8 @@ filter Get-GitHubRepositoryCollaborator Gets a list of collaborators for the PowerShellForGithub repository. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryCollaboratorTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -1818,7 +1820,7 @@ filter Get-GitHubRepositoryCollaborator [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -1907,11 +1909,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')] @@ -1932,7 +1931,7 @@ filter Get-GitHubRepositoryLanguage [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -2016,11 +2015,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')] @@ -2041,7 +2037,7 @@ filter Get-GitHubRepositoryTag [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -2134,7 +2130,6 @@ filter Move-GitHubRepositoryOwnership DefaultParameterSetName='Elements')] [OutputType({$script:GitHubRepositoryTypeName})] [Alias('Transfer-GitHubRepositoryOwnership')] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -2161,7 +2156,7 @@ filter Move-GitHubRepositoryOwnership [switch] $NoStatus ) - Write-InvocationLog -Invocation $MyInvocation + Write-InvocationLog $elements = Resolve-RepositoryElements $OwnerName = $elements.ownerName @@ -2178,6 +2173,13 @@ 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 + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/transfer" 'Body' = (ConvertTo-Json -InputObject $hashBody) @@ -2429,6 +2431,8 @@ filter Enable-GitHubRepositoryVulnerabilityAlert [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2438,24 +2442,24 @@ 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 - - $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) - } + return + } - 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 @@ -2546,6 +2550,8 @@ filter Disable-GitHubRepositoryVulnerabilityAlert [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2555,24 +2561,24 @@ 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 - - $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) - } + return + } - 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 @@ -2663,6 +2669,8 @@ filter Enable-GitHubRepositorySecurityFix [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2672,24 +2680,24 @@ 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 - - $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) - } + return + } - 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 @@ -2779,6 +2787,8 @@ filter Disable-GitHubRepositorySecurityFix [switch] $NoStatus ) + Write-InvocationLog + $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters $OwnerName = $elements.ownerName $RepositoryName = $elements.repositoryName @@ -2788,24 +2798,24 @@ 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 - - $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) - } + return + } - Invoke-GHRestMethod @params | Out-Null + $params = @{ + UriFragment = "repos/$OwnerName/$RepositoryName/automated-security-fixes" + Description = "Disabling Automated Security Fixes for $RepositoryName" + AcceptHeader = $script:londonAcceptHeader + Method = 'Delete' + AccessToken = $AccessToken + TelemetryEventName = $MyInvocation.MyCommand.Name + TelemetryProperties = $telemetryProperties + NoStatus = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters ` + -Name NoStatus -ConfigValueName DefaultNoStatus) } + + Invoke-GHRestMethod @params | Out-Null } filter Add-GitHubRepositoryAdditionalProperties diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 18a3ca31..dbeaee70 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -63,11 +63,8 @@ filter Get-GitHubRepositoryFork Gets all of the forks for the microsoft\PowerShellForGitHub repository. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubRepositoryTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -191,7 +188,6 @@ filter New-GitHubRepositoryFork SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubRepositoryTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] [string] $OwnerName, @@ -232,6 +228,11 @@ filter New-GitHubRepositoryFork $getParams += "organization=$OrganizationName" } + if (-not $PSCmdlet.ShouldProcess($RepositoryName, 'Forking GitHub Repository')) + { + return + } + $params = @{ 'UriFragment' = "repos/$OwnerName/$RepositoryName/forks`?" + ($getParams -join '&') 'Method' = 'Post' diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 606b64d6..3c5ba17e 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -69,11 +69,8 @@ filter Get-GitHubReferrerTraffic Get the top 10 referrers over the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubReferrerTrafficTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -185,11 +182,8 @@ filter Get-GitHubPathTraffic Get the top 10 popular contents over the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubPathTrafficTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -307,11 +301,8 @@ filter Get-GitHubViewTraffic Get the total number of views and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubViewTrafficTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] @@ -433,11 +424,8 @@ filter Get-GitHubCloneTraffic Get the total number of clones and breakdown per day or week for the last 14 days from the microsoft\PowerShellForGitHub project. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubCloneTrafficTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter(ParameterSetName='Elements')] diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 07d38454..33a632ed 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -72,11 +72,8 @@ filter Get-GitHubTeam .EXAMPLE Get-GitHubTeam -OrganizationName PowerShell #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='Elements')] + [CmdletBinding(DefaultParameterSetName = 'Elements')] [OutputType({$script:GitHubTeamTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param ( @@ -212,11 +209,8 @@ filter Get-GitHubTeamMember .EXAMPLE $members = Get-GitHubTeamMember -Organization PowerShell -TeamName Everybody #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='ID')] + [CmdletBinding(DefaultParameterSetName = 'ID')] [OutputType({$script:GitHubUserTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param ( [Parameter( diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 16019b45..b0e9163a 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -72,11 +72,8 @@ filter Get-GitHubUser Gets information on the current authenticated user. #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='ListAndSearch')] + [CmdletBinding(DefaultParameterSetName = 'ListAndSearch')] [OutputType({$script:GitHubUserTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( @@ -186,11 +183,8 @@ filter Get-GitHubUserContextualInformation Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 70 | Get-GitHubUserContextualInformation -User octocat #> - [CmdletBinding( - SupportsShouldProcess, - DefaultParameterSetName='NoContext')] + [CmdletBinding(DefaultParameterSetName = 'NoContext')] [OutputType({$script:GitHubUserContextualInformationTypeName})] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( [Parameter( @@ -355,7 +349,6 @@ function Set-GitHubProfile [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubUserTypeName})] [Alias('Update-GitHubCurrentUser')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [string] $Name, @@ -387,6 +380,11 @@ function Set-GitHubProfile if ($PSBoundParameters.ContainsKey('Bio')) { $hashBody['bio'] = $Bio } if ($PSBoundParameters.ContainsKey('Hireable')) { $hashBody['hireable'] = $Hireable.ToBool() } + if (-not $PSCmdlet.ShouldProcess('Update Current GitHub User')) + { + return + } + $params = @{ 'UriFragment' = 'user' 'Method' = 'Patch' diff --git a/Helpers.ps1 b/Helpers.ps1 index 5d1b5ef7..87526b1a 100644 --- a/Helpers.ps1 +++ b/Helpers.ps1 @@ -123,8 +123,7 @@ function Write-Log to make sense. In this case, the cmdlet should accumulate the messages and, at the end, include the exception information. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Justification="We need to be able to access the PID for logging purposes, and it is accessed via a global variable.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidOverwritingBuiltInCmdlets", "", Justification="Write-Log is an internal function being incorrectly exported by PSDesiredStateConfiguration. See PowerShell/PowerShell#7209")] param( @@ -248,7 +247,7 @@ function Write-Log } else { - $logFileMessage | Out-File -FilePath $Path -Append + $logFileMessage | Out-File -FilePath $Path -Append -WhatIf:$false -Confirm:$false } } } @@ -322,7 +321,7 @@ function Write-InvocationLog ExcludeParameter will always take precedence over RedactParameter. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] param( [Management.Automation.InvocationInfo] $Invocation = (Get-Variable -Name MyInvocation -Scope 1 -ValueOnly), diff --git a/Telemetry.ps1 b/Telemetry.ps1 index 857bc373..3c9b94c5 100644 --- a/Telemetry.ps1 +++ b/Telemetry.ps1 @@ -139,7 +139,8 @@ function Invoke-SendTelemetryEvent Invoke-* methods share a common base code. Leaving this as-is to make this file easier to share out with other PowerShell projects. #> - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Justification="We use global variables sparingly and intentionally for module configuration, and employ a consistent naming convention.")] param( [Parameter(Mandatory)] [PSCustomObject] $TelemetryEvent @@ -153,11 +154,6 @@ function Invoke-SendTelemetryEvent $body = ConvertTo-Json -InputObject $TelemetryEvent -Depth $jsonConversionDepth -Compress $bodyAsBytes = [System.Text.Encoding]::UTF8.GetBytes($body) - if (-not $PSCmdlet.ShouldProcess($uri, "Invoke-WebRequest")) - { - return - } - try { Write-Log -Message "Sending telemetry event data to $uri [Timeout = $(Get-GitHubConfiguration -Name WebRequestTimeoutSec))]" -Level Verbose @@ -296,8 +292,9 @@ function Set-TelemetryEvent Because of the short-running nature of this module, we always "flush" the events as soon as they have been posted to ensure that they make it to Application Insights. #> - [CmdletBinding(SupportsShouldProcess)] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', + Justification='Function is not state changing')] param( [Parameter(Mandatory)] [string] $EventName, @@ -392,8 +389,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,