You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
I would like to create a pipeline which, on commit, will open a PR with the forked repository
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.
...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.