-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PowerShellForGitHub: Improve and Standardise WhatIf/Confirm Processing #254
PowerShellForGitHub: Improve and Standardise WhatIf/Confirm Processing #254
Conversation
eee34e6
to
79c3530
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). |
@@ -139,7 +139,8 @@ 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(SupportsShouldProcess)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.ShouldProcess
check out ofInvoke-GHRestMethod
and added it to the calling functions with the correct operation and target.WhatIf:$false
andConfirm:$false
to theOut-File
Cmdlet call in theWrite-Log
function in the Helpers module. This will prevent theWrite-Log
function displayingWhatIf
andConfirm
prompts.ShouldProcess
from non-state changing functions.ShouldProcess
conditions to use an early return.Set-GitHubIssueLabel
function to removeConfirmImpact='High'
and setConfirmPreference
to 'Low' if no labels have been specified instead.Update-GitHubRepository
function to removeConfirmImpact='High'
and setConfirmPreference
to '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