Last active
March 6, 2019 15:19
-
-
Save OliverJAsh/06ac17b9dacff7a15f5c084c11cfd57d to your computer and use it in GitHub Desktop.
`git merge-pr`: CLI for merging GitHub PRs (via API) with completions
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
#compdef git-merge-pr | |
_git-merge-pr () { | |
# Note: requires hub and jq to be installed | |
# https://developer.github.com/v3/pulls/#list-pull-requests | |
# hub api /repos/{owner}/{repo}/pulls | |
PRS=$( | |
hub api /repos/{owner}/{repo}/pulls \ | |
| jq 'map({title, number, head})' | |
) | |
PRS_DETAIL_STRING=$( | |
echo $PRS \ | |
| jq --raw-output 'map((.number | tostring) + ": " + .head.ref + ", " + .title) | .[]' | |
) | |
# https://unix.stackexchange.com/questions/29724/how-to-properly-collect-an-array-of-lines-in-zsh | |
# TODO: avoid leaking IFS? | |
IFS=$'\n' PRS_DETAIL=($(echo "$PRS_DETAIL_STRING")) | |
_describe 'pull request' PRS_DETAIL | |
} |
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 | |
# Note: requires hub and jq to be installed | |
# If a script errors, force the script to fail immediately. | |
set -e | |
ID=$1 | |
# https://unix.stackexchange.com/questions/225943/except-the-1st-argument/225951#225951 | |
REST=${@:2} | |
PR_PATH="repos/{owner}/{repo}/pulls/$ID" | |
echo "Merging $ID" | |
# https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button | |
echo $REST | xargs hub api -XPUT $PR_PATH/merge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment