Last active
November 10, 2020 14:52
-
-
Save joshdholtz/fd95b29b206e8932563a936aed807e0f to your computer and use it in GitHub Desktop.
gh pr push <pr_number>
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
# Pushes to the remote that the PR was created from | |
# Useful for open source projects that allows maintainers to edit | |
# Requires "brew install jq" | |
# Requires "brew install github/gh/gh" | |
function pr_push { | |
ORG_AND_REPO=$(git remote get-url origin | sed 's/.*\/\([^ ]*\/[^.]*\).*/\1/') | |
REMOTE_URL=$(curl https://api.github.com/repos/$ORG_AND_REPO/pulls/${1:?"The PR number must be specified"} | jq .head.repo.clone_url | tr -d '"') | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
echo "Going to execute: git push $REMOTE_URL $BRANCH" | |
$(git push $REMOTE_URL $BRANCH) | |
} | |
# Push equivalent of https://cli.github.com/manual/gh_pr_checkout | |
# gh pr push <pr_number> | |
gh() { | |
if [ "$1" = "pr" ] && [ "$2" = "push" ]; then | |
pr_push $3 | |
else | |
command gh "$@" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment