Skip to content

Instantly share code, notes, and snippets.

@eliranmal
Forked from devongovett/pull_request.sh
Last active February 28, 2017 00:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliranmal/fee365b2b416fe9ac0ab55b3fa1a75df to your computer and use it in GitHub Desktop.
Save eliranmal/fee365b2b416fe9ac0ab55b3fa1a75df to your computer and use it in GitHub Desktop.
Bash script to make a pull request from the current git repository.
#!/usr/bin/env bash
pull_request() {
local to_branch="$1"
if [ -z $to_branch ]; then
to_branch="master"
fi
local access_token="[some access token with lots of characters]"
local root_endpoint="https://api.github.com"
local origin="$(git config --get remote.origin.url)"
local user="$(echo "$origin" | sed -e 's/.*[\/:]\([^/]*\)\/[^/]*$/\1/')"
local repo="$(basename `git rev-parse --show-toplevel`)"
local from_branch="$(git rev-parse --abbrev-ref HEAD)"
curl -i \
-H 'Authorization: token '"$access_token" \
-H 'Accept: application/vnd.github.v3+json' \
-d '{
"title": "Amazing new feature",
"body": "Please pull this in!",
"head": "'"$from_branch"'",
"base": "'"$to_branch"'"
}' \
-L https://"$root_endpoint"/repos/"$user"/"$repo"/pulls
}
pull_request "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment