cli / cli

GitHub’s official command line tool
https://cli.github.com
MIT License
37.29k stars 5.79k forks source link

let user select pr to checkout (or more) when listing them with `pr list` #2329

Open EugenMayer opened 4 years ago

EugenMayer commented 4 years ago

Describe the feature or problem you’d like to solve

It is a little cumbersome to always first check the pr one is looking for using pr list, then find out the pr number and then write it all out again using pr checkout <number>.

It would be so great if one could be able to interactively select a pr, when they are listed using pr list.

This would make switching PR's a lot easier ( not only solving the task using 1 cli command, instead of for - far more important is that you do not need to remember the number you just saw )

Proposed solution

I understand, that interactive selections like this might be hindering some automation uses - or might be. So i would make this either a opt-in feature, a argument like --selection or similar.

If in any form interested, one can argue that selecting a pr could end up having several reasons like

If that is the common idea, we might have a 2 level select, means first select a pr, then the action.

I'am not sure about the current primary mission of gh-cli, be it automation or human-usage (like i happily do daily). If automation is the primary mission, non interactive should be the default, otherwise the other way around might be better.

samcoe commented 4 years ago

@EugenMayer Thanks for the feedback and feature request. I know that @mislav is really interested in making our list commands more actionable, and we have a couple design ideas that we are investigating. We will make sure to evaluate a two level select approach, as you suggested.

drewbrokke commented 4 years ago

If I may cast my vote, I think that gh should remain non-interactive by default. I've had the experience of a non-interactive tool introducing interaction by default with an update, and it essentially made the tool useless for my scripts that were using it.

I agree the ability to act on the output is very valuable, and in this I appreciate that gh has provided so many ways of retrieving and viewing data (e.g., the gh api command). It has made it very easy to use gh with tools like fzf and jq to create my own interactive script for pull requests, as an example: https://gist.github.com/drewbrokke/702a5711e71cb49e0807d41e6e7395d3.

jeffg-hpe commented 3 years ago

With peco you can do:

$ gh pr list | peco | awk '{print $1}' | xargs gh pr checkout

Or as an alias:

$ alias pr="gh pr list | peco | awk '{print $1}' | xargs gh pr checkout && gh pr view"
$ pr

It's not as pretty as a native gh solution, as we have to fall back to machine output mode for the pr list and lose the nice formatting.

EugenMayer commented 3 years ago

I implemented this myself using https://github.com/manifoldco/promptui and i think this is fairly sleek:

if no PR id is provided as arg, i trigger the interactive selection in the cli (instead of throwing error). If the PR id is provided i just pick the given numeric one and continue (the current workflow without changes)

This way, we do not need to discuss here if "automated use" is the mission or "user convenience" - it would cover both without blocking it.

I have written my own cli tool utilizing github.com/google/go-github/v33 and the above, it should be very easy to implement here using the rest api included here (since we already can list PRs)

So my question at the maintainers: a) Is there any interest for this feature b) Can i use an external dependency https://github.com/manifoldco/promptui to implement the selection

If both are answered with yes, i'am happy to provide a PR implementing this - let me know. I case of b) is a no, i would opt out for creating a PR, i do not like to reinvent the wheel (IMHO)

mislav commented 3 years ago

@EugenMayer Thanks for sharing your approach!

a) Is there any interest for this feature

When it comes to “outside“ contributions, no. Since this issue is marked as core, per our CONTRIBUTING guidelines, our team prefers making a decision and work on the implementation of this internally.

b) Can i use an external dependency https://github.com/manifoldco/promptui to implement the selection

That would also be a no, since we already use the AlecAivazis/survey UI library for prompts, and it looks like these libraries have a lot of overlap in what they do. We would rather stick to a single UI library than depend on multiple ones.

vilmibm commented 1 year ago

Going to open this up with this specific design:

See gh run view's implementation for a similar approach.

trustin commented 1 year ago

Here's the script I'm using for exactly this purpose; it requires fzf and jq:

nilvng commented 4 days ago

Hey there, just a heads up that I've started working on this issue, the PR is #9868 Feel free to review and add your input :)