about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-02-23 17:43:50 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-02-23 17:43:50 +0100
commitc9cf9c95209ba3bf4000ebd3632b9d096dae1646 (patch)
treeb3e6b2b887bacd866485b69734caa3cf03c3263a
parent62862e30c107f4058d64900e4f32755108fba7a8 (diff)
downloadgit-merge-pr-c9cf9c95209ba3bf4000ebd3632b9d096dae1646.tar.gz
git-merge-pr-c9cf9c95209ba3bf4000ebd3632b9d096dae1646.tar.xz
git-merge-pr-c9cf9c95209ba3bf4000ebd3632b9d096dae1646.zip
List pull requests when no PRNUM is given
-rwxr-xr-xgit-merge-pr14
1 files 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