-
-
Save cstrahan/b429ffc4c70bbb59d63f 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
# Start working on a pull request, this requires a .git/user-repo file | |
# containing the string "user/repository" | |
pr() { | |
local pr_num=$1 | |
if [[ -z $pr_num ]]; then | |
echo "Need the pull request number" >&2 | |
return 1 | |
fi | |
if [[ ! -r .git/user-repo ]]; then | |
echo "Need to setup user/repo" >&2 | |
return 1 | |
fi | |
if [[ -e .git/current-pull-request ]]; then | |
echo "Already working on pull request $(< .git/current-pull-request)" >&2 | |
return 1 | |
fi | |
( | |
set -e | |
local user_repo=$(< .git/user-repo) | |
curl "https://github.com/$(< .git/user-repo)/pull/$pr_num.patch" 2> /dev/null | git am | |
echo $pr_num > .git/current-pull-request | |
echo "Working on PR $pr_num" | |
) | |
} | |
# Finish working on a pull request, besides the .git/user-repo file, | |
# this requires a .git/ghtok file containing the oauth token for accessing the | |
# repository and a .git/current-pull-request created by the `pr` function | |
cpr() { | |
if [[ ! -r .git/ghtok ]]; then | |
echo "Need to setup oauth token" >&2 | |
return 1 | |
fi | |
if [[ ! -r .git/user-repo ]]; then | |
echo "Need to setup user/repo" >&2 | |
return 1 | |
fi | |
if [[ ! -r .git/current-pull-request ]]; then | |
echo "Not working on a pull request" >&2 | |
return 1 | |
fi | |
local pr_num=$(< .git/current-pull-request) | |
( | |
set -e | |
rm .git/current-pull-request | |
echo "Will push commits and comment/close on PR $pr_num" | |
git push | |
curl \ | |
-X POST \ | |
-H "Authorization: token $(< .git/ghtok)" \ | |
-d '{"body": ":+1: merged, thanks"}' \ | |
"https://api.github.com/repos/$(< .git/user-repo)/issues/$pr_num/comments" > /dev/null | |
curl \ | |
-X PATCH \ | |
-H "Authorization: token $(< .git/ghtok)" \ | |
-d '{"state": "closed"}' \ | |
"https://api.github.com/repos/$(< .git/user-repo)/issues/$pr_num" > /dev/null | |
echo "Done" | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment