Created
September 17, 2014 18:37
-
-
Save ConradIrwin/c8a8f2468f3aa3f1e347 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # | |
| # Fetch a pull request from github. Guesses the name of your repo from its `origin` | |
| # remote. | |
| # | |
| # e.g. git fetch-pr 8 | |
| # | |
| # (relies on `wip/git-url` and `jq` for now) | |
| set -e | |
| t="$(mktemp -t XXXXX.json)" | |
| function json() { | |
| cat $t | jq -r "$@" | |
| } | |
| echo "Fetching $(git url --api /pulls/$1)" | |
| curl --netrc -sS $(git url --api /pulls/$1) > $t | |
| if [ "$(json .message)" != "null" ] | |
| then | |
| echo "$(json .message)" | |
| else | |
| echo "Fetching $(json .head.repo.owner.login)/$(json .head.ref)" | |
| git fetch "$(json .head.repo.ssh_url)" "$(json .head.ref)" | |
| git branch "$(json .head.repo.owner.login)/$(json .head.ref)" "$(json .head.sha)" | |
| fi | |
| rm $t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment