Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Source branch not deleted after merge with API

drichards-alcon August 5, 2020

Looking at the REST API documentation setting close_source_branch:true should delete the source branch after a Pull request has been merged.

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/merge

 

I create a new branch with changes:

curl -sk -X POST -u 'user:pass' --url 'https://api.bitbucket.org/2.0/repositories/alconpc/cdit-dnr-test-1/src' -F "message=testing rest $(date) [skip ci]" -F 'branch=feature/rest-test' -F 'parents=develop' -F '/documents/config-file-one.yml=@a' -F '/documents/config-file-new.yml=@a'

I validate this works on the BB GUI, next I create the PR:

curl -sk -X POST -u 'user:pass' --url 'https://api.bitbucket.org/2.0/repositories/alconpc/cdit-dnr-test-1/pullrequests' -H 'Content-Type: application/json' --data '{"close_source_branch":true,"description":"automated process to update config files via REST","destination":{"branch":{"name":"develop"}},"source":{"branch":{"name":"feature/rest-test"}},"title":"Update config files date","type": "pullrequest"}' | jq .
{
"rendered": {
"description": {............

I also verify that the PR was created with the delete branch option

 curl -sk -X GET -u 'user:pass' --url 'https://api.bitbucket.org/2.0/repositories/alconpc/cdit-dnr-test-1/pullrequests/7' | jq .close_source_branch
true

So I expect that when I merge the PR it will delete feature/rest-test

 curl -sk -X POST -u 'user:pass' --url 'https://api.bitbucket.org/2.0/repositories/alconpc/cdit-dnr-test-1/pullrequests/7/merge' | jq .
{
"rendered": {
"description": {

However it is not deleted :(

I am not sure what I am doing incorrectly so that it is not deleting.

 

2 answers

1 accepted

0 votes
Answer accepted
drichards-alcon August 5, 2020

I have also tried adding the close_source_branch to the merge:

curl -ski -X POST -u 'user:pass' --url 'https://api.bitbucket.org/2.0/repositories/alconpc/cdit-dnr-test-1/pullrequests/3/merge' --data '{"close_source_branch":true,"type":"pullrequest"}'

and it does not help.

drichards-alcon August 10, 2020

The above does work if you remember to include

Content-Type: application/json 

in the headers ;)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events