Skip to content

Instantly share code, notes, and snippets.

@beausmith
Last active December 29, 2016 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beausmith/1317029dd6b90f3d2acf5ac586cff665 to your computer and use it in GitHub Desktop.
Save beausmith/1317029dd6b90f3d2acf5ac586cff665 to your computer and use it in GitHub Desktop.
Pull Request from
#!/usr/bin/env bash
set -e
urlencode() {
read
local length="${#REPLY}"
for (( i = 0; i < length; i++ )); do
local c="${REPLY:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c"
esac
done
}
if [ $# == 0 ]; then
current_branch=$(git rev-parse --abbrev-ref HEAD | urlencode )
repo_url=$(git config remote.origin.url | sed -e 's/^git@\(.*\):\(.*\)$/git:\/\/\1\/\2/' | sed -e 's/^.*\/\/\(.*\).git$/\1/' | sed -e 's/\git@//')
host=$(echo $repo_url | awk 'BEGIN { FS="/" } ; { print $1 }' | awk 'BEGIN { FS=":" }; { print $1 }')
project=$(echo $repo_url | awk 'BEGIN { FS="/" } ; { print $2 }')
repo=$(echo $repo_url | awk 'BEGIN { FS="/" } ; { print $3 }')
# Launch GitHub pull request url.
url="https://$repo_url/compare/master...$current_branch?expand=1#files_bucket"
open $url
else
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" == "pr/$1" ]; then
git checkout master
fi
git fetch origin pull/$1/head:pr/$1
git checkout pr/$1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment