-
-
Save beausmith/1317029dd6b90f3d2acf5ac586cff665 to your computer and use it in GitHub Desktop.
Pull Request from
This file contains 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
#!/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