Skip to content

Commit 55ed0f5

Browse files
committed
Add back -WhatIf support to core methods until #254 is in.
1 parent cee2215 commit 55ed0f5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

GitHubCore.ps1

+12-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function Invoke-GHRestMethod
105105
This wraps Invoke-WebRequest as opposed to Invoke-RestMethod because we want access
106106
to the headers that are returned in the response, and Invoke-RestMethod drops those headers.
107107
#>
108-
[CmdletBinding()]
108+
[CmdletBinding(SupportsShouldProcess)]
109109
param(
110110
[Parameter(Mandatory)]
111111
[string] $UriFragment,
@@ -194,6 +194,11 @@ function Invoke-GHRestMethod
194194
$headers.Add("Content-Type", "application/json; charset=UTF-8")
195195
}
196196

197+
if (-not $PSCmdlet.ShouldProcess($url, "Invoke-WebRequest"))
198+
{
199+
return
200+
}
201+
197202
$originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
198203

199204
try
@@ -527,7 +532,7 @@ function Invoke-GHRestMethodMultipleResult
527532
but the request happens in the foreground and there is no additional status
528533
shown to the user until a response is returned from the REST request.
529534
#>
530-
[CmdletBinding()]
535+
[CmdletBinding(SupportsShouldProcess)]
531536
[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.")]
532537
[OutputType([Object[]])]
533538
param(
@@ -552,6 +557,11 @@ function Invoke-GHRestMethodMultipleResult
552557
[switch] $NoStatus
553558
)
554559

560+
if (-not $PSCmdlet.ShouldProcess($UriFragment, "Invoke-GHRestMethod"))
561+
{
562+
return
563+
}
564+
555565
$AccessToken = Get-AccessToken -AccessToken $AccessToken
556566

557567
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

Telemetry.ps1

+6-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function Invoke-SendTelemetryEvent
139139
Invoke-* methods share a common base code. Leaving this as-is to make this file
140140
easier to share out with other PowerShell projects.
141141
#>
142-
[CmdletBinding()]
142+
[CmdletBinding(SupportsShouldProcess)]
143143
param(
144144
[Parameter(Mandatory)]
145145
[PSCustomObject] $TelemetryEvent
@@ -153,6 +153,11 @@ function Invoke-SendTelemetryEvent
153153
$body = ConvertTo-Json -InputObject $TelemetryEvent -Depth $jsonConversionDepth -Compress
154154
$bodyAsBytes = [System.Text.Encoding]::UTF8.GetBytes($body)
155155

156+
if (-not $PSCmdlet.ShouldProcess($uri, "Invoke-WebRequest"))
157+
{
158+
return
159+
}
160+
156161
try
157162
{
158163
Write-Log -Message "Sending telemetry event data to $uri [Timeout = $(Get-GitHubConfiguration -Name WebRequestTimeoutSec))]" -Level Verbose

0 commit comments

Comments
 (0)