Merging a pull-request without specifying a body overwrites close_source_branch value

Issue #17883 new
Mark Tarry
created an issue

When merging a pull-request, via the Bitbucket REST API, if no body is provided then the original close_source_branch value (on the PR) is both ignored, and overwritten.

According to the API documentation:

close_source_branch boolean Whether the source branch should be deleted. If this is not provided, we fallback to the value used when the pull request was created, which defaults to False*

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

Steps to replicate

  • Create a pull-request, and specify close_source_branch
POST https://api.bitbucket.org/2.0/repositories/<owner>/<slug>/pullrequests
{   ...
    "close_source_branch": true
}
  • Retrieve the pull request - confirm that close_source_branch is still true
GET https://api.bitbucket.org/2.0/repositories/<owner>/<slug>/pullrequests/<id>
  • Merge the PR, without a request body
POST https://api.bitbucket.org/2.0/repositories/<owner>/<slug>/pullrequests/<id>/merge
  • Retrieve the pull request
GET https://api.bitbucket.org/2.0/repositories/<owner>/<slug>/pullrequests/<id>

Expected: close_source_branch is still true, and the source branch was closed after the merge was completed

Actual: close_source_branch is overwritten to be false, and the source branch remains open after the merge was completed

Comments (1)

  1. Mark Tarry reporter

    Workaround

    I've confirmed that if the merge request contains a body - which repeats the original close_source_branch value - then the PR works as expected.

    POST https://api.bitbucket.org/2.0/repositories/<owner>/<slug>/pullrequests/<id>/merge
    {
        "close_source_branch": true
    }
    
  2. Log in to comment