Search code examples
azure-devopsazure-pipelinesazure-devops-rest-api

Modify MR merge commit message through Azure DevOps API


In order to introduce a proper workflow for our team in Azure DevOps, I am trying to find a way to set the merge commit message of a merge request to the title of the merge request. For some reason, Azure DevOps sets the merge commit message by default to Merged PR#: <title>, adding an undesired prefix to the message. This beheviour cannot be customized, as described in this (5-year old) issue in Microsoft Developer Community. Recently, someone suggested in this thread to use Azure DevOps's API from a build pipeline to set a customized message. I have tried with success to reach the API from my pipeline, but I cannot find a way to have my custom message be registered in Azure DevOps.

When I send a request with the proper merge options (as described in this piece of documentation), the API returns the updated pull request information.

For example, when I send a request with this body :

{
    "completionOptions": {
        "mergeStrategy": "squash",
        "mergeCommitMessage": "something"
    }
}

the API properly returns the pull request data :

{
    <...PR data...>
    "completionOptions": {
        "mergeCommitMessage": "something",
        "squashMerge": true,
        "mergeStrategy": "squash"
    }
    <...more PR data...>
}

so I assume the message has been updated. But when I go to my pending merge request on Azure DevOps, the message is the same as before: PR merge commit message

When I untick the "Customize merge commit message" box and proceed with the merge, the behaviour is the same and my customized message (with is basically the merge request title) is not kept.

Am I missing some additional information to put in the request ? Or does the web interface of Azure DevOps overwrite my options for some reason?


Solution

  • The completionOptions is applied only when you set the PR to be auto completed.

    You need to add this to your body:

    "autoCompleteSetBy":  {
        "id":  "7a9a9b44-a2f1-6dfd-a7f6-54354353453"
     }     
    

    The "id" should be the user who created the PR - Project Build User Account.

    Result:

    enter image description here