about summary refs log tree commit diff
diff options
context:
space:
mode:
-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