Last active
December 16, 2015 14:19
-
-
Save acammack/5447900 to your computer and use it in GitHub Desktop.
minihub: a small shell wrapper for working with github
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/sh | |
## Usage: | |
# minihub checkout|fetch|pull|push username branchname | |
# Fetch and checkout, fetch, pull, push, or checkout a user's branch, if you | |
# have access | |
# minihub pull-request|pr username basebranch title [message] | |
# Submit a pull request for the current HEAD to the user's base branch. If | |
# successful, it will print out the URL of the new PR. | |
# | |
# All of these commands assume that the repository name can be found in the | |
# .git/description file. The username and login are set just a little ways | |
# below. Git and curl will prompt for your password as needed. | |
set -e | |
login="[email protected]" | |
username="johndoe" | |
git_root=$(git rev-parse --show-toplevel ) | |
repo_name=$(cat ${git_root}/.git/description) | |
case $1 in | |
fetch|pull|push) | |
git $1 [email protected]:$2/${repo_name}.git $3 | |
;; | |
checkout) | |
git fetch [email protected]:$2/${repo_name}.git $3 | |
git checkout FETCH_HEAD | |
;; | |
pull-request|pr) | |
# You can only open pull requests for commits that have been pushed, | |
# ie, you can't be in a detached head state | |
head=$(cat ${git_root}/.git/HEAD | sed -e 's|ref: refs/heads/||') | |
cat <<JSON | | |
{ | |
"title": "$4", | |
"body": "$5", | |
"base": "$3", | |
"head": "${username}:${head}" | |
} | |
JSON | |
curl -sS -u ${login} -X POST https://api.github.com/repos/$2/${repo_name}/pulls -d @- |\ | |
grep html_url |\ | |
head -1 |\ | |
sed -e 's/.*: "\(.*\)",/\1/' | |
;; | |
*) | |
echo "I don't know how to $1" | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment