Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.