Created
March 20, 2015 17:24
-
-
Save blalor/1b89da7a524968bc2824 to your computer and use it in GitHub Desktop.
Bitbucket shell tools
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/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