Created
November 8, 2016 21:09
-
-
Save KanjiMonster/ec15174bb61fba555020bded4e8bb1ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
REPO=$1 | |
PR=$2 | |
PATCH=$3 | |
if [ "$REPO" = "auto" ]; then | |
REPO=$(git config --get remote.origin.url) | |
case "$REPO" in | |
https://github.com*) | |
REPO=${REPO#https://github.com/} | |
;; | |
[email protected]:*) | |
REPO=${REPO#[email protected]:} | |
;; | |
*) | |
echo "Unrecognised repository format: $REPO" | |
;; | |
esac | |
REPO=${REPO%.git} | |
fi | |
[ -n "$REPO" ] || exit 1 | |
URIS=$(curl -s https://api.github.com/repos/$REPO/pulls/$PR/commits | sed -ne 's|^.*"html_url": "\(.*/commit/.*\)",|\1.patch|p') | |
i=1 | |
for uri in $URIS; do | |
filename=$(printf pr_%i_%03i.patch $PR $i) | |
if [ -z "$PATCH" -o "$i" = "$PATCH" ]; then | |
echo $filename | |
curl -s -o $filename $uri | |
fi | |
i=$((i + 1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment