Visitar URL original
Add `lock` and `unlock` commands for issues and pull requests by chemotaxis · Pull Request #5333 · cli/cli · GitHub
The Wayback Machine - https://web.archive.org/web/20220627102422/https://github.com/cli/cli/pull/5333
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

Add lock and unlock commands for issues and pull requests #5333

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from

Conversation

chemotaxis
Copy link
Contributor

@chemotaxis chemotaxis commented Mar 21, 2022 •

Fixes #5020.

This pull request adds lock and unlock to issues and pull requests.

unlock will unlock a conversation if it was previously locked. Otherwise, it will do nothing.

lock will lock a conversation if it was previously unlocked. You can optionally specify a reason for locking from a set of fixed reasons.

If the issue or pull request is already locked, gh will prompt you to confirm if you want to "relock" a conversation or abort the "relock" if you forgot or didn't know the conversation was already locked. The primary use for relocking will probably be to change the lock reason.

I tried just sending a lock request again with an updated reason, but nothing changes. You first have to unlock the conversation, then lock it with the updated reason.

The error messages are parameterized on several variables including the parent command (issue or pr), what the intended action was (lock or unlock), the reason for locking, etc. For example, if issue #1 exists, but we used the command gh pr lock 1, the error message will say that issue #1 exists, but not pull request #1. It then suggests to use gh issue lock 1 instead.

Lock will lock and unlock both issues and pull requests
chemotaxis added 7 commits Apr 11, 2022
As originally designed in the issue discussion, a single function
`NewCmdLock()` with a parameter to lock or unlock was proposed.
However, after playing around with a couple different designs, it seems
best to create two separate public functions and one private function to
do the common work.

Using two public functions seems to make sense because the api for
locking is different from the api for unlocking.  Therefore, the
documentation for both are different and keeping them in separate
functions would make it easier to maintain the documentation.
- Changed function to method
- Moved additional common options to method
- Remove redundant documentation
    - Cobra sets documentation in the Command struct.
These are needed to know if an issue is an actual issue or a pull
request.
Add queries for "ActiveLockReason" and "Locked"
@chemotaxis chemotaxis force-pushed the gh-issue-lock branch 2 times, most recently from b88ffa2 to c1f98dc Compare Apr 11, 2022
chemotaxis added 11 commits Apr 29, 2022
- Fix error if found an issue while using `gh pr lock/unlock` or vice versa
- Added additional types
- Used githubv4 types
- Added "relock" state
    - If the conversation is already locked you have two choices: try to
      lock it again or do nothing.  Do nothing is easy.  But, if you
      want to change the lock reason, you need to first unlock the
      conversation and then lock it again.
- Added survey to confirm if you want to relock
- Added formatted print statements
- Switch to underscores
- Revise error message
Rather than saving the intended lock state and calling a method
depending on the lock state, just call the method directly.  By the time
you need to the padlock state, you already know which method to use; no
need to first change the lock state than call the method.

Also, refactored print/error messages that are conditional.
I noticed that PadlockState didn't really have anything to do with the
LockOptions and it was easy to call an incorrect locking function that
didn't match the PadlockState.

Now, you pass in the state as an argument and you simply call the
appropriate function instead of setting PadlockState and then calling
the correct function.

- Other touch ups and refactoring
Use switch statements for regular branching code.
As much as I like keeping statements as flat as possible, this
not-as-flat revision just seems easier to read.
@chemotaxis
Copy link
Contributor Author

@chemotaxis chemotaxis commented Apr 29, 2022

I apologize if the history on this pull request is a little messy, but I went through several drafts before arriving at this final draft version. I haven't written any tests yet, but I wanted to see if the overall behavior was acceptable.

Some notes:

There seem to be several methods with overlapping functionality in issue/shared and pr/shared, so it was a little confusing at first to find the most appropriate function to request information about an issue or pull request.

It was also somewhat tricky to address two separate functions (lock/unlock) and two separate types (issues/pull requests) simultaneously. Hopefully my current solution addresses everything fairly cleanly.

Finally, since the current version of gh doesn't support querying/mutating the lock state or active lock reason, I needed to add a couple new fields to the Issue type. Consequently, gh doesn't display the locked state or lock reason. I plan to create a new issue in order to add lock-related information to issue view, pr view, at least.

@chemotaxis chemotaxis marked this pull request as ready for review Apr 29, 2022
@chemotaxis chemotaxis requested a review from as a code owner Apr 29, 2022
@chemotaxis chemotaxis requested review from mislav (assigned from cli/code-reviewers) and removed request for Apr 29, 2022
@cliAutomation cliAutomation added the external label Apr 29, 2022
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external
Projects
The GitHub CLI
  
Needs review 🤔
Development

Successfully merging this pull request may close these issues.

3 participants