PowerShellForGitHub: Improve and Standardise WhatIf/Confirm Processing#254
Conversation
eee34e6 to
79c3530
Compare
HowardWolosky
left a comment
There was a problem hiding this comment.
A few lingering questions/nits, and then there's the need to handle the merge conflict in GitHubCore.ps1 and Telemetry.ps1 introduced by the recent change that removed Status.
|
Also -- please let me know in what order you'd prefer your changes to go in...if you're wanting this one to go in before your other changes or after. |
HowardWolosky
left a comment
There was a problem hiding this comment.
After looking through this one more time, I think there is a flaw in the pattern of putting Write-InvocationLog after the $PSCmdlet.ShouldProcess() check...there are a number of functions that do validation work and will write error messages to the console/log file in the event that there was a problem. Those lines will all print without an logged invocation entry, which could both confusing as well as detrimental (no way to review the passed-in parameters).
I think that the $PSCmdlet.ShouldProcess() checks should remain where they are, but that the Write-InvocationLog entries should go back to their original spots.
6efea0a to
fafb237
Compare
|
@HowardWolosky, this is ready for the next review. |
HowardWolosky
left a comment
There was a problem hiding this comment.
Thanks for your patience here and all the hard work. Ready to get this merged in now.
|
/azp run PowerShellForGitHub-CI |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| 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)] |
There was a problem hiding this comment.
This change is causing the tests to fail right now, because we still have the check at line 157 that calls $PSCmdlet.ShouldProcess():
Invoke-SendTelemetryEvent' calls ShouldProcess/ShouldContinue but does not have the ShouldProcess attribute.
Stack trace
at line: 157 in /home/vsts/work/1/s/Telemetry.ps1
ShouldProcess
Severity: Warning
There was a problem hiding this comment.
Removed ShouldProcessBlock
|
/azp run PowerShellForGitHub-CI |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
There are 7 UT failures with this change (all 7 are consistently failing across all 4 targets, 2 additionals are one-off issues I believe). All 7 are in the GitHubBranches.tests.ps1, most likely around usage of |
|
@HowardWolosky, I've remove the redundant |
|
/azp run PowerShellForGitHub-CI |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Nice to get this in. Thanks so much for spearheading this effort, @X-Guardian! |
Description
This PR improves and standardises the WhatIf/Confirm ('ShouldProcess') processing across all the functions.
Summary of changes
$PSCmdlet.ShouldProcesscheck out ofInvoke-GHRestMethodand added it to the calling functions with the correct operation and target.WhatIf:$falseandConfirm:$falseto theOut-FileCmdlet call in theWrite-Logfunction in the Helpers module. This will prevent theWrite-Logfunction displayingWhatIfandConfirmprompts.ShouldProcessfrom non-state changing functions.ShouldProcessconditions to use an early return.Set-GitHubIssueLabelfunction to removeConfirmImpact='High'and setConfirmPreferenceto 'Low' if no labels have been specified instead.Update-GitHubRepositoryfunction to removeConfirmImpact='High'and setConfirmPreferenceto 'Low' if the repo is being renamed instead.Issues Fixed
References
N/A
Checklist
Comment-based help added/updated, including examples.Changes to the manifest file follow the manifest guidance.Unit tests were added/updated and are all passing. See testing guidelines. This includes making sure that all pipeline input variations have been covered.Relevant usage examples have been added/updated in USAGE.md.If desired, ensure your name is added to our Contributors list