Skip to content

Instantly share code, notes, and snippets.

@jow-
Created June 5, 2016 10:45
Show Gist options
  • Save jow-/cd0127746cca14d2a7c4622706604b54 to your computer and use it in GitHub Desktop.
Save jow-/cd0127746cca14d2a7c4622706604b54 to your computer and use it in GitHub Desktop.
A script to convert pull requests into patch files for git-am
#!/bin/sh
REPO=$1
PR=$2
PATCH=$3
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