From c9cf9c95209ba3bf4000ebd3632b9d096dae1646 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Tue, 23 Feb 2016 17:43:50 +0100 Subject: List pull requests when no PRNUM is given --- git-merge-pr | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/git-merge-pr b/git-merge-pr index bcba973..4e59fe8 100755 --- a/git-merge-pr +++ b/git-merge-pr @@ -1,15 +1,14 @@ #!/bin/sh -# git merge-pr PRNUM[@REMOTE] [GIT-AM FLAGS...] - apply GitHub pull request from command-line +# git merge-pr [PRNUM][@REMOTE] [GIT-AM FLAGS...] - list or apply GitHub pull request from command-line set -e -PR=${1?no pull request given} +PR=$1 REMOTE= case "$PR" in *@*) REMOTE=${PR#*@} PR=${PR%%@*} esac -shift URL=$(git ls-remote --get-url $REMOTE) @@ -17,6 +16,15 @@ PROJECT=${URL%.git} PROJECT=${PROJECT##*:} PROJECT=${PROJECT#//github.com/} +if [ -z "$PR" ]; then + wget -q -O- --header 'Accept: application/json' \ + "https://api.github.com/repos/${PROJECT}/pulls?direction=asc" | + jq -r '.[] | "\(.number) <\(.user.login)> \(.title)"' + exit $? +else + shift +fi + PATCH="$(mktemp)" trap "rm -f $PATCH" INT TERM EXIT wget -nv -O "$PATCH" https://github.com/$PROJECT/pull/"$PR".patch -- cgit 1.4.1