danobi / prr

Mailing list style code reviews for github
GNU General Public License v2.0
295 stars 18 forks source link

Add support for listing Open PRs #7

Closed rkeene closed 10 months ago

rkeene commented 2 years ago

Increasing the scope of the project slightly, if it allowed a user to list open PRs it would reduce the need to go to GitHub.com's Web Interface and get a list of PRs or use a separate tool for that aspect of review.

danobi commented 2 years ago

Seems reasonable

reneegyllensvaan commented 2 years ago

Just FYI, while this tool doesn't support it, there are good tools out there that do! There's both the older, unofficial hub CLI, and the official cli tool.

I can only really speak for hub, as it's what I use, but it's absolutely lovely for writing CLI-based automation and workflows. hub pr list will accomplish what you're looking for here. hub has a slightly different model, where instead of taking a repo path, it infers the URL from (presumably) your git remotes, which is pretty neat.

The below is a wrapper script I'm using around hub and prr (also fzy is in there for interactive use). In non-interactive mode, the handy part is that it lets you do git prr get 1234 instead of prr get myself/myrepo/1234.

git-prr:

#!/bin/sh
recents_file="$HOME/.local/share/prr/_recent"
action="$1"
shift
number="$1"
shift
if [ ! "$action" = "get" ] && [ ! "$action" = "submit" ]; then
  echo "Usage: git prr <get|submit> [number]"
  exit
fi

set -e
url="$(hub browse --url 2>/dev/null || (echo 'Not in a github repo' >&2 && exit))"
repo_path="$(echo "$url" | sed -En 's~^.*\.[a-z]+/([^/]*/[^/]*).*$~\1~p')"

# If no `number` argument is provided, offer a selection of what's available using `fzy`
if [ "$action" = "get" ]; then
  if [ -z "$number" ]; then
    # Prompt for which PR to review
    choices="$(hub pr list)"
    choice_line="$(echo "$choices" | fzy)"
    number="$(echo "$choice_line" | sed -E 's/ *#([0-9]+).*/\1/g')"
    echo "$repo_path|$choice_line" >> "$recents_file"
  else
    echo "$repo_path|$number" >> "$recents_file"
  fi
  file="$(prr $action "$repo_path/$number")"
  # Print the file to stdout so we see it when the editor fails/exits
  echo $file
  "${VISUAL:-EDITOR}" "$file"
else
  # Offer to submit any PRs that have recently been accessed
  choices="$(sed -En 's~^'"$repo_path"'\|(.*)~\1~p' "$recents_file")"
  choice_line="$(echo "$choices" | fzy)"
  number="$(echo "$choice_line" | sed -E 's/ *#([0-9]+).*/\1/g')"
  prr $action "$repo_path/$number"
fi

On top of that, hub has an excellent subcommand for creating new PRs with the same workflow as for making commits (hub pull-request, edit title and message, :wq, you're done), absolutely recommend trying it out.

keevan commented 2 years ago

+1 for @reneegyllensvaan's point

There are plenty of tools which does this already and would be an additional pain to maintain if brought into scope.

Speaking from github's CLI gh side of things, there is a command which lists out the available PRs / issues, etc.

https://cli.github.com/manual/gh_pr_list gh pr list

Perhaps this project can point to the other CLI tool(s) for functionality not provided directly by this project but would be useful in combination.

danobi commented 10 months ago

Thinking again, I agree with above commenters. Good tools already exist for this job