Skip to content

Instantly share code, notes, and snippets.

@blalor
Created March 20, 2015 17:24
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 blalor/1b89da7a524968bc2824 to your computer and use it in GitHub Desktop.
Save blalor/1b89da7a524968bc2824 to your computer and use it in GitHub Desktop.
Bitbucket shell tools
#!/bin/bash
set -e -u
title="$1"
username=$( jq -r .user $HOME/.bitbucket_creds )
password=$( jq -r .passwd $HOME/.bitbucket_creds )
# get repo name from the current repo
repo_name=$( git config remote.origin.url | sed -E -e 's#^.*:(.*)\.git#\1#g' )
current_branch=$( git rev-parse --abbrev-ref HEAD )
payload_format='{
"title": "%s",
"source": { "branch": { "name": "%s" } },
"close_source_branch": true
}'
payload=$( printf "${payload_format}" "${title}" "${current_branch}" )
curl -s -f -v \
-X POST \
-H "Content-Type: application/json" \
--user "${username}:${password}" \
https://bitbucket.org/api/2.0/repositories/${repo_name}/pullrequests \
-d "${payload}" \
| jq -r ".links.html.href"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment