Merge Pull Request API is not overriding merge strategy

Issue #16784 invalid
Mark Cerezo
staff created an issue

Summary

Using PR merge API doesn't enforce or overrides the "merge_strategy" field, the API follows the default merge strategy set in the repository settings. To add, the API doesn't also overrides the "message" field.

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

How to reproduce

  1. Change your repository default merge strategy (under your repository > settings) to "Merge commit"
  2. Create a new Pull request
  3. Use the API CURL command below to merge (using "squash") your PR by providing the PR ID Sample CURL command:
curl --request POST \
  --url https://api.bitbucket.org/2.0/repositories/username/repositoryurl/pullrequests/pr_Id/merge \
  --header 'authorization: Basic <HASH>' \
  --header 'cache-control: no-cache' \
  --header 'content-type: application/json' \
  --data '{
    "pullrequest_merge_parameters": {
        "type": "pullrequest",
        "message": "Sample commit message",
        "close_source_branch": "false",
        "merge_strategy": "squash"
    }
}'

Expected Results

The merge API should overrides / enforce the "merge_strategy" to "squash" the commit set in the API

Actual Results

The merge API is using the default merge strategy set in the repository settings

Workaround

For now, we can manually set the merge strategy in repository settings to change

Official response

  • Anna Li-Fatou staff

    This happens to be a misinterpretation of our api docs. Try passing in just the value of ‘pullrequest_merge_parameters’.

    For example,

     --data '{
            "type": "pullrequest",
            "message": "Sample commit message",
            "close_source_branch": "false",
            "merge_strategy": "squash"
        }'
    

Comments (5)

  1. Rajendra Kumar

    Also the commit message sent in the curl is not overriding the default commit message added by api. Can we change the priority of this jira and get this fixed asap ? As we are adding automation around this for the whole company and due to this issue it is corrupting the commit messages and merge strategies from the automation.

  2. Ajaya Agrawal

    @Mark Cerezo There are multiple issues here.

    • merge_strategy field not being honored.
    • message field not being honored

    While there is a work-around for the first problem, there is no work-around for the second problem. Could please provide an ETA for the second problem? Independent of the fix, please change your documentation so that other users don't end up discovering the same problem again independently.

  3. Anna Li-Fatou staff

    This happens to be a misinterpretation of our api docs. Try passing in just the value of ‘pullrequest_merge_parameters’.

    For example,

     --data '{
            "type": "pullrequest",
            "message": "Sample commit message",
            "close_source_branch": "false",
            "merge_strategy": "squash"
        }'
    
  4. Erik van Zijst staff

    Note that the type of the request body is not "pullrequest" and the "type" element can be omitted.

    This endpoint is odd in that it isn't restful (the path contains a verb and it doesn't take the same object schema it returns). It's really an RPC endpoint.

    @Anna Li-Fatou is right about the layout of the request body.

  5. Log in to comment