Description
Issue Details
Since PR #213, the ShouldProcess
(WhatIf/Confirm) processing in the module is better, but it still could be improved.
The PowerShellForGuthub
functions are designed to be consumed by other scripts/functions,
so the norm in this case is for each function to only ever output a single ShouldProcess
prompt.
Currently, most functions output at least two prompts, for example:
PS> New-GitHubRepository -OrganizationName test -RepositoryName test -WhatIf
What if: Performing the operation "Output to File" on target "\\nas01\data\users\simon\documents\PowerShellForGitHub.log".
What if: Performing the operation "Invoke-WebRequest" on target "https://api.github.com/orgs/test/repos".
The WhatIf
for the 'Output to File' should not be shown, and the second WhatIf
has a non-useful operation and target. It should be: What if: Performing the operation "Create Repository" on target "test"
.
Also, if a function is given an invalid set of parameters, for example:
New-GitHubRepository -RepositoryName test -TeamId 1 -WhatIf
What if: Performing the operation "Output to File" on target "\\nas01\data\users\simon\documents\PowerShellForGitHub.log".
Exception: Z:\Users\Simon\Documents\GitHub\X-Guardian\PowerShellForGitHub\GitHubRepositories.ps1:144:9
Line |
144 | throw $message
| ~~~~~~~~~~~~~~
| TeamId may only be specified when creating a repository under an organization.
The WhatIf
for the 'Output to File' should not be shown.
Suggested solution to the issue
- Move the
$PSCmdlet.ShouldProcess
check out ofInvoke-GHRestMethod
and add it to the calling functions with the correct operation and target (as has been done for theConfirmHighImpact
PR Add confirmation prompts and examples for Remove- functions #174). - Move the
Write-InvocationLog -Invocation $MyInvocation
line in each resource function to within the$PSCmdlet.ShouldProcess
condition block. This will prevent the log being updated ifShouldProcess
is $false. - Add
-WhatIf:$false
to theOut-File
Cmdlet call in theWrite-Log
function in theHelpers
module. This will prevent theWrite-Log
function displayingWhatIf
.
This would also have the additional benefit of being able to remove the SuppressMessageAttribute
PSShouldProcess
decorator from all the functions, as the ShouldProcess
logic will now be happening within the function.
Requested Assignment
- If possible, I would like to fix this.
Operating System
OsName : Microsoft Windows 10 Pro
OsOperatingSystemSKU : 48
OsArchitecture : 64-bit
WindowsVersion : 1903
WindowsBuildLabEx : 18362.1.amd64fre.19h1_release.190318-1202
OsLanguage : en-GB
OsMuiLanguages : {en-GB, en-US}
PowerShell Version
Name Value
---- -----
PSVersion 7.0.1
PSEdition Core
GitCommitId 7.0.1
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module Version
Running: 0.14.0
Installed: 0.14.0