Last active
September 25, 2019 07:11
-
-
Save lrytz/28dd202acfa06f4d1155fda3cdc0ee3a to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -e | |
[[ $# == 1 ]] || { | |
echo "usage: $0 <pr-number>" | |
exit 1 | |
} | |
pr=$1 | |
upstream=$(git remote -v | grep -E '^upstream\s+' | head -1 | sed 's/upstream.*github.com.\(.*\)\.git.*/\1/') | |
git fetch upstream pull/$pr/head -f | |
git checkout pr$pr 2> /dev/null || git checkout -b pr$pr | |
git reset --hard FETCH_HEAD | |
prInfo=$(curl -s https://api.github.com/repos/$upstream/pulls/$pr) | |
remoteName=$(echo -E $prInfo | jq -r '.head.user.login') | |
git remote -v | grep -E "^$remoteName\s+" > /dev/null || { | |
remoteUrl=$(echo -E $prInfo | jq -r '.head.repo.ssh_url') | |
echo "Adding remote $remoteName - $remoteUrl" | |
git remote add $remoteName $remoteUrl | |
} | |
branch=$(echo -E $prInfo | jq -r '.head.ref') | |
git fetch -f $remoteName $branch | |
base=$(echo -E $prInfo | jq -r '.base.sha') | |
git rebase -i $base | |
git push -f $remoteName HEAD:$branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment