Skip to content

PowerShellForGitHub: Improve and Standardise WhatIf/Confirm Processing #248

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

Closed
wants to merge 1 commit into from
Closed

PowerShellForGitHub: Improve and Standardise WhatIf/Confirm Processing #248

wants to merge 1 commit into from

Conversation

X-Guardian
Copy link
Contributor

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

This PR is superseded by PR #254

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.
  • Moved the Write-InvocationLog line in each resource function to after the $PSCmdlet.ShouldProcess condition block. This will prevent the log being updated if ShouldProcess is $false.
  • 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

@X-Guardian
Copy link
Contributor Author

Ran the whole test suite for this PR, and the GitHubRepositoryForks test has deleted my fork of the PowerShellForGitHub repo, which includes all the branches for the pending PRs here including this one :(

@HowardWolosky
Copy link
Contributor

Ran the whole test suite for this PR, and the GitHubRepositoryForks test has deleted my fork of the PowerShellForGitHub repo, which includes all the branches for the pending PRs here including this one :(

Oh no. I've immediately merged in #251 to avoid this in the future. So sorry about that.

@HowardWolosky HowardWolosky added the enhancement An issue or pull request introducing new functionality to the project. label Jun 28, 2020
@HowardWolosky
Copy link
Contributor

Any idea how to fix the PRs?

Not sure yet. Doing some searching online. Will be able to look a bit more this afternoon.

@HowardWolosky
Copy link
Contributor

I don't think you can.

https://stackoverflow.com/questions/36071272/fix-unknown-repository-of-an-opened-pr-after-deleted-the-fork
isaacs/github#168

I think you'll just need to create new pull requests for those outstanding ones, and then close out the ones that have now been orphaned.

Copy link
Contributor

@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.

Overall this looks good. Thanks for the effort.
A couple nits, and then a few that referenced the wrong value.

@HowardWolosky HowardWolosky added the waiting for update Waiting for an update to the PR before the next review label Jun 29, 2020
@HowardWolosky
Copy link
Contributor

Actually, looking at this a bit more as full files as opposed to just the diffs, I think the one thing about the pattern that I'd change is that I'd move the check to the top of the functions as opposed to right before the call to Invoke-GHRestMethod*.

@X-Guardian
Copy link
Contributor Author

Actually, looking at this a bit more as full files as opposed to just the diffs, I think the one thing about the pattern that I'd change is that I'd move the check to the top of the functions as opposed to right before the call to Invoke-GHRestMethod*.

If you are running a function with the WhatIf parameter, the main purpose is to validate that the set of parameters you have passed are valid. To achieve this, the $PSCmdlet.ShouldProcess statement needs to occur after all the parameter validation code.

@HowardWolosky
Copy link
Contributor

If you are running a function with the WhatIf parameter, the main purpose is to validate that the set of parameters you have passed are valid. To achieve this, the $PSCmdlet.ShouldProcess statement needs to occur after all the parameter validation code.

Sufficiently compelling argument for me. Please keep as-is.

@X-Guardian
Copy link
Contributor Author

This PR is superseded by PR #254

@X-Guardian X-Guardian closed this Jun 29, 2020
@HowardWolosky HowardWolosky added superseded The PR was replaced by a newer PR and removed waiting for update Waiting for an update to the PR before the next review labels Jun 29, 2020
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. superseded The PR was replaced by a newer PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PowerShellForGitHub: Suggested WhatIf/Confirm Processing Improvements
2 participants