Last active
November 9, 2019 14:43
-
-
Save piranha/2820032 to your computer and use it in GitHub Desktop.
Script to create pull requests right from the shell
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
#!/bin/sh | |
# git-req -- make a pull request | |
# | |
# Assumes branch is pushed to same repo as pull request is made to (origin) | |
# | |
# How to obtain GITREQ_TOKEN: | |
# | |
# curl -u "$USER:$PASSWORD" -d '{"scopes": ["repo"], "note": "git-req"}' https://api.github.com/authorizations | |
# | |
# Usage: | |
# | |
# git req # for defaults | |
# git req 'Another title' | |
# git req '' 'Another body' | |
# | |
# Defaults: pushes current branch to a repo and creates a pull request to same | |
# repo (intent: code review), with subject of latest commit as title and body as | |
# body. | |
[ -z "$GITREQ_TOKEN" ] && echo "set GITREQ_TOKEN in your environment" && exit 1 | |
API=https://api.github.com | |
TITLE=${1:-$(git log --pretty=format:'%s' -1)} | |
BODY=${2:-$(git log --pretty=format:'%b' -1)} | |
BRANCH=$(git symbolic-ref --short HEAD) | |
DEST=$(git config --get remote.origin.url | \ | |
awk -F : '{ gsub(/.git$/, "", $2); print $2 }') | |
request() { | |
DATA="{'title': '$2', 'base': 'master', 'head': '$1', 'body': '$3'}" | |
DATA=$(echo $DATA | sed s/\'/\"/g) | |
AUTH="Authorization: bearer $GITREQ_TOKEN" | |
curl -s -H "$AUTH" -d "$DATA" $API/repos/$DEST/pulls | \ | |
awk '/"html_url".*pull/ { gsub(/"/, "", $2); print $2 }' | |
} | |
git push origin $BRANCH && request "$BRANCH" "$TITLE" "$BODY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment