Skip to content
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

Merged
merged 15 commits into from
Aug 3, 2020

Conversation

X-Guardian
Copy link
Contributor

@X-Guardian X-Guardian commented Jun 29, 2020

Description

This PR improves and standardises the WhatIf/Confirm ('ShouldProcess') processing across all the functions.

Summary of changes
  • Moved the $PSCmdlet.ShouldProcess check out of Invoke-GHRestMethod and added it to the calling functions with the correct operation and target.
  • Added WhatIf:$false and Confirm:$false to the Out-File Cmdlet call in the Write-Log function in the Helpers module. This will prevent the Write-Log function displaying WhatIf and Confirm prompts.
  • Removed ShouldProcess from non-state changing functions.
  • Modified the current ShouldProcess conditions to use an early return.
  • Modified the Set-GitHubIssueLabel function to remove ConfirmImpact='High' and set ConfirmPreference to 'Low' if no labels have been specified instead.
  • Modified the Update-GitHubRepository function to remove ConfirmImpact='High' and set ConfirmPreference to 'Low' if the repo is being renamed instead.

Issues Fixed

References

N/A

Checklist

  • You actually ran the code that you just wrote, especially if you did just "one last quick change".
  • Comment-based help added/updated, including examples.
  • Static analysis is reporting back clean.
  • New/changed code adheres to our coding guidelines.
  • New/changed code continues to support the pipeline.
  • 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

@HowardWolosky HowardWolosky added the enhancement An issue or pull request introducing new functionality to the project. label Jun 29, 2020
@X-Guardian X-Guardian force-pushed the ShouldProcess-Update branch from eee34e6 to 79c3530 Compare June 29, 2020 16:45
@X-Guardian X-Guardian marked this pull request as ready for review June 29, 2020 16:46
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jun 30, 2020
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jun 30, 2020
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jun 30, 2020
Copy link
Member

@HowardWolosky HowardWolosky left a 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.

GitHubConfiguration.ps1 Outdated Show resolved Hide resolved
GitHubConfiguration.ps1 Outdated Show resolved Hide resolved
GitHubConfiguration.ps1 Outdated Show resolved Hide resolved
GitHubConfiguration.ps1 Show resolved Hide resolved
GitHubLabels.ps1 Show resolved Hide resolved
GitHubLabels.ps1 Show resolved Hide resolved
GitHubLabels.ps1 Show resolved Hide resolved
GitHubPullRequests.ps1 Outdated Show resolved Hide resolved
GitHubRepositories.ps1 Show resolved Hide resolved
Helpers.ps1 Show resolved Hide resolved
@HowardWolosky
Copy link
Member

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 HowardWolosky added the waiting for update Waiting for an update to the PR before the next review label Jul 2, 2020
Copy link
Member

@HowardWolosky HowardWolosky left a 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.

GitHubConfiguration.ps1 Outdated Show resolved Hide resolved
GitHubConfiguration.ps1 Outdated Show resolved Hide resolved
GitHubProjectCards.ps1 Outdated Show resolved Hide resolved
GitHubProjectColumns.ps1 Outdated Show resolved Hide resolved
GitHubProjects.ps1 Outdated Show resolved Hide resolved
GitHubRepositories.ps1 Outdated Show resolved Hide resolved
GitHubUsers.ps1 Outdated Show resolved Hide resolved
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jul 8, 2020
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jul 15, 2020
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jul 15, 2020
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jul 16, 2020
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jul 18, 2020
HowardWolosky added a commit to HowardWolosky/PowerShellForGitHub that referenced this pull request Jul 19, 2020
@X-Guardian X-Guardian force-pushed the ShouldProcess-Update branch from 6efea0a to fafb237 Compare July 21, 2020 17:14
@X-Guardian
Copy link
Contributor Author

@HowardWolosky, this is ready for the next review.

Copy link
Member

@HowardWolosky HowardWolosky left a 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.

GitHubConfiguration.ps1 Outdated Show resolved Hide resolved
@HowardWolosky
Copy link
Member

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky HowardWolosky removed the waiting for update Waiting for an update to the PR before the next review label Jul 30, 2020
@@ -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)]
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed ShouldProcessBlock

@HowardWolosky HowardWolosky added the waiting for update Waiting for an update to the PR before the next review label Jul 30, 2020
@HowardWolosky
Copy link
Member

/azp run PowerShellForGitHub-CI

HowardWolosky
HowardWolosky previously approved these changes Jul 31, 2020
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky
Copy link
Member

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 -WhatIf in Get-* functions...

Expected an exception, with message 'Origin branch Missing-Branch not found' to be thrown, but the message was 'A parameter cannot be found that matches parameter name 'Whatif'.'. from /home/vsts/work/1/s/GitHubBranches.ps1:300 char:53
at <ScriptBlock>, /home/vsts/work/1/s/Tests/GitHubBranches.tests.ps1: line 221
at <ScriptBlock>, /home/vsts/work/1/s/Tests/GitHubBranches.tests.ps1: line 235

@X-Guardian
Copy link
Contributor Author

@HowardWolosky, I've remove the redundant WhatIf/Confirm parameters. Can you re-run the CI?

@HowardWolosky
Copy link
Member

/azp run PowerShellForGitHub-CI

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HowardWolosky HowardWolosky merged commit 2f16de1 into microsoft:master Aug 3, 2020
@HowardWolosky
Copy link
Member

Nice to get this in. Thanks so much for spearheading this effort, @X-Guardian!

@X-Guardian X-Guardian deleted the ShouldProcess-Update branch April 19, 2023 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An issue or pull request introducing new functionality to the project. waiting for update Waiting for an update to the PR before the next review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PowerShellForGitHub: Suggested WhatIf/Confirm Processing Improvements
2 participants