2

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for your answer, I have tried your solution, but I encounter the following error : Invalid pull request auto complete set by id. Valid values are either the current user identity id, or an empty guid (to unset auto complete). It seems that I need to use the ID of the build account, but the variable Build.QueuedBy contains Microsoft.VisualStudio.Services.TFS and using Build.QueuedById raises the same error. The proper permissions are set for the build account.
did you put the id of who created the PR?
Yes, but it didn't work. I finally managed to make it work by choosing the originId of our project's build account !
Great! so the id should be the if of the project's build account?
@Ebig, thanks for getting back! Yes, I also found that out by now. Regarding auth, I have supplied a Bearer token that I have obtained form az account get-access-token.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.