Skip to content

Instantly share code, notes, and snippets.

@KanjiMonster
Created November 8, 2016 21:09
Show Gist options
  • Save KanjiMonster/ec15174bb61fba555020bded4e8bb1ca to your computer and use it in GitHub Desktop.
Save KanjiMonster/ec15174bb61fba555020bded4e8bb1ca to your computer and use it in GitHub Desktop.
#!/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/}
;;
git@github.com:*)
REPO=${REPO#git@github.com:}
;;
*)
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