You can do it via API calls and a shell script. Here are some bash functions I wrote as part of a script that should get you started, the functions assume $srcBranch, $tgtBranch, $repo, $userName and $password are set:
function getPullRequestPostData() {
cat <<EOF
{
"title": "$title",
"source": {
"branch": {
"name": "$srcBranch"
}
},
"destination": {
"branch": {
"name": "$tgtBranch"
}
}
}
EOF
}
function openPR() {
echo "Opening PR for repo: $repo"
response=$(curl --write-out %{http_code} --silent --output /dev/null https://api.bitbucket.org/2.0/repositories/YourWorkspace/$repo/pullrequests \
-u $userName:$password \
--request POST \
--header "Content-Type: application/json" \
--data "$(getPullRequestPostData)")
result=0
if [ "$response" -ne "200" ] && [ "$response" -ne "201" ]; then
echo "ERROR: Status code is $response"
result=-1
fi
return $result
}
Thank you @Jay Seletz ! I will give this a try. Quick question - is the shell script able to load your $variables directly from the BitBucket repository variables?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I recommend you wrap these functions in your own shell script and pass bitbucket variables into the shell script as command line args. Then you can also run/test it locally first easier.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My answer below.. I had to specify "repository" in the source object since the PR was coming from a fork apparently:
title=$1
srcBranch=$2
tgtBranch=$3
repo=$4
userName=$5
password=$6
# echo "Title: $title"
# echo "srcBranch: $srcBranch"
# echo "tgtBranch: $tgtBranch"
# echo "repo: $repo"
# echo "userName: $userName"
# echo "password: $password"
function getPullRequestPostData() {
cat <<EOF
{
"title": "Automated Pull Request",
"source": {
"branch": {
"name": "$srcBranch"
},
"repository": {
"full_name":"$userName/$repo"
}
},
"destination": {
"branch": {
"name": "$tgtBranch"
}
}
}
EOF
}
function openPR() {
echo "Opening PR for repo: $repo"
response=$(curl https://api.bitbucket.org/2.0/repositories/[target repo org]/$repo/pullrequests \
-u $userName:$password \
--request POST \
--header 'Content-Type: application/json' \
--data "$(getPullRequestPostData)" \
)
result=0
if [ "$response" -ne "200" ] && [ "$response" -ne "201" ]; then
echo "ERROR: Status code is $response"
result=-1
fi
return $result
}
openPR
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.