Skip to content

Commit 7c04aa0

Browse files
committed
2 parents 5c04c79 + 98aec29 commit 7c04aa0

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CONTRIBUTING.md

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Looking for information on how to use this module? Head on over to [README.md](
2222
* [Coding Guidelines](#coding-guidelines)
2323
* [Adding New Configuration Properties](#adding-new-configuration-properties)
2424
* [Code Comments](#code-comments)
25+
* [Debugging Tips](#debugging-tips)
2526
* [Testing](#testing)
2627
* [Installing Pester](#installing-pester)
2728
* [Configuring Your Environment](#configuring-your-environment)
@@ -270,6 +271,17 @@ code that reads clearly while requiring minimal comments to understand what it's
270271

271272
----------
272273

274+
### Debugging Tips
275+
276+
You may find it useful to configure the module to log the body of all REST requests during
277+
development of a new feature, to make it easier to see exactly what is being sent to GitHub.
278+
279+
```powershell
280+
Set-GitHubConfiguration -LogRequestBody
281+
```
282+
283+
----------
284+
273285
### Testing
274286
[![Build status](https://ci.appveyor.com/api/projects/status/vsfq8kxo2et2dn7i?svg=true
275287
)](https://ci.appveyor.com/project/HowardWolosky/powershellforgithub)

GitHubConfiguration.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ function Set-GitHubConfiguration
114114
log entry. This can be useful if you have concurrent PowerShell sessions all logging
115115
to the same file, as it would then be possible to filter results based on ProcessId.
116116
117+
.PARAMETER LogRequestBody
118+
If specified, the JSON body of the REST request will be logged to verbose output.
119+
This can be helpful for debugging purposes.
120+
117121
.PARAMETER LogTimeAsUtc
118122
If specified, all times logged will be logged as UTC instead of the local timezone.
119123
@@ -180,6 +184,8 @@ function Set-GitHubConfiguration
180184

181185
[switch] $LogProcessId,
182186

187+
[switch] $LogRequestBody,
188+
183189
[switch] $LogTimeAsUtc,
184190

185191
[int] $RetryDelaySeconds,
@@ -262,6 +268,7 @@ function Get-GitHubConfiguration
262268
'DisableTelemetry',
263269
'LogPath',
264270
'LogProcessId',
271+
'LogRequestBody',
265272
'LogTimeAsUtc',
266273
'RetryDelaySeconds',
267274
'SuppressNoTokenWarning',
@@ -593,6 +600,7 @@ function Import-GitHubConfiguration
593600
'defaultRepositoryName' = [String]::Empty
594601
'logPath' = $logPath
595602
'logProcessId' = $false
603+
'logRequestBody' = $false
596604
'logTimeAsUtc' = $false
597605
'retryDelaySeconds' = 30
598606
'suppressNoTokenWarning' = $false

GitHubCore.ps1

+18-2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ function Invoke-GHRestMethod
200200
$bodyAsBytes = [System.Text.Encoding]::UTF8.GetBytes($Body)
201201
$params.Add("Body", $bodyAsBytes)
202202
Write-Log -Message "Request includes a body." -Level Verbose
203+
if (Get-GitHubConfiguration -Name LogRequestBody)
204+
{
205+
Write-Log -Message $Body -Level Verbose
206+
}
203207
}
204208

205209
[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
@@ -217,7 +221,7 @@ function Invoke-GHRestMethod
217221
if ($PSCmdlet.ShouldProcess($jobName, "Start-Job"))
218222
{
219223
[scriptblock]$scriptBlock = {
220-
param($Url, $Method, $Headers, $Body, $ValidBodyContainingRequestMethods, $TimeoutSec, $ScriptRootPath)
224+
param($Url, $Method, $Headers, $Body, $ValidBodyContainingRequestMethods, $TimeoutSec, $LogRequestBody, $ScriptRootPath)
221225

222226
# We need to "dot invoke" Helpers.ps1 and GitHubConfiguration.ps1 within
223227
# the context of this script block since we're running in a different
@@ -239,6 +243,10 @@ function Invoke-GHRestMethod
239243
$bodyAsBytes = [System.Text.Encoding]::UTF8.GetBytes($Body)
240244
$params.Add("Body", $bodyAsBytes)
241245
Write-Log -Message "Request includes a body." -Level Verbose
246+
if ($LogRequestBody)
247+
{
248+
Write-Log -Message $Body -Level Verbose
249+
}
242250
}
243251

244252
try
@@ -272,7 +280,15 @@ function Invoke-GHRestMethod
272280
}
273281
}
274282

275-
$null = Start-Job -Name $jobName -ScriptBlock $scriptBlock -Arg @($url, $Method, $headers, $Body, $ValidBodyContainingRequestMethods, (Get-GitHubConfiguration -Name WebRequestTimeoutSec), $PSScriptRoot)
283+
$null = Start-Job -Name $jobName -ScriptBlock $scriptBlock -Arg @(
284+
$url,
285+
$Method,
286+
$headers,
287+
$Body,
288+
$ValidBodyContainingRequestMethods,
289+
(Get-GitHubConfiguration -Name WebRequestTimeoutSec),
290+
(Get-GitHubConfiguration -Name LogRequestBody),
291+
$PSScriptRoot)
276292

277293
if ($PSCmdlet.ShouldProcess($jobName, "Wait-JobWithAnimation"))
278294
{

0 commit comments

Comments
 (0)