Skip to content

Commit

Permalink
Add back -WhatIf support to core methods until #254 is in.
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardWolosky committed Jun 30, 2020
1 parent 4576cae commit 7881d7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 12 additions & 2 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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()]
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory)]
[string] $UriFragment,
Expand Down Expand Up @@ -194,6 +194,11 @@ function Invoke-GHRestMethod
$headers.Add("Content-Type", "application/json; charset=UTF-8")
}

if (-not $PSCmdlet.ShouldProcess($url, "Invoke-WebRequest"))
{
return
}

$originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol

try
Expand Down Expand Up @@ -527,7 +532,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()]
[CmdletBinding(SupportsShouldProcess)]
[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(
Expand All @@ -552,6 +557,11 @@ function Invoke-GHRestMethodMultipleResult
[switch] $NoStatus
)

if (-not $PSCmdlet.ShouldProcess($UriFragment, "Invoke-GHRestMethod"))
{
return
}

$AccessToken = Get-AccessToken -AccessToken $AccessToken

$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
Expand Down
7 changes: 6 additions & 1 deletion Telemetry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Invoke-SendTelemetryEvent
Invoke-* methods share a common base code. Leaving this as-is to make this file
easier to share out with other PowerShell projects.
#>
[CmdletBinding()]
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory)]
[PSCustomObject] $TelemetryEvent
Expand All @@ -153,6 +153,11 @@ 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
Expand Down

0 comments on commit 7881d7d

Please sign in to comment.