Skip to content

Instantly share code, notes, and snippets.

@dblevins
Last active Dec 4, 2018
Embed
What would you like to do?
#!/bin/bash
##-----------------------------------------
##
## Small script to help make it slightly faster
## to apply Github PRs to a local clone.
##
## Purl is short for PR URL. Usage is simple:
##
## $ cd tomee-site-generator
## $ purl https://github.com/apache/tomee-site-generator/pull/7
##
## You must still ensure your local repo is up
## to date and ready for work.
##
## Check for script updates: https://gist.github.com/dblevins/6e255634d84914beb051a4b3858ebfb4
##
##-----------------------------------------
URL="${1?Specify the Github PR url}"
# Grab the user and branch name
PR=($(curl -s "$URL" | \
tr '\n' ' ' | \
perl -pe 's,.*<span class="css-truncate-target user">([^>]+)</span>:<span class="css-truncate-target">([^>]+)</span></span>.*,$1 $2,g'
))
# Pull the repo name from the remote list
REPO=$(git remote -v | grep 'origin.*push' | perl -pe 's,.*[:/]([a-zA-Z0-9-]+).git .push.,$1,')
# Now apply the PR
echo git pull git@github.com:"${PR[0]}"/"$REPO".git "${PR[1]}"
git pull git@github.com:"${PR[0]}"/"$REPO".git "${PR[1]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment