#!/usr/bin/env bash # # Echo and exit # abort() { echo $@ exit 1 } # # Produce json with , <body>, <head> and <base> # json() { local title="${1//\"/\\\"}" local body="${2//\"/\\\"}" local head="${3//\"/\\\"}" local base="${4//\"/\\\"}" cat <<EOF { "title": "$title", "body": "$body", "head": "$head", "base": "$base" } EOF } # user user=$(git config --global user.email) test -z "$user" && abort "git config user.email required" # branch branch=${1-$(git symbolic-ref HEAD | sed 's/refs\/heads\///')} # make sure it's pushed git push origin $branch || abort "failed to push $branch" # lame hack to get project origin=$(git config remote.origin.url) if [[ $origin == git@* ]]; then project=${origin##*:} else project=${origin#https://*/} fi project=${project%.git} # prompt echo echo " create pull-request for $project '$branch'" echo printf " title: " && read title printf " body: " && read body printf " base [master]: " && read base echo # create pull request if [ -z "$base" ] then base="master" fi body=$(json "$title" "$body" $branch "$base") curl -u "$user" "https://api.github.com/repos/$project/pulls" -d "$body"