Search code examples
azureazure-devopsazure-repos

How to edit title of a pull request which is already merged in Azure repos?


I have a pull request, which is already marked as "Completed" but I would like to edit the title of that pull request. I cannot find the option to edit it.

I have already searched on different platforms if this option is disabled by any settings but still no luck.


Solution

  • It is not possible to update title of PR that have been completed. You can neither from the web UI nor use Azure DevOps API/CLI to update the title of completed PR.

    I tried to call the API "Pull Requests - Update" to update the title of a completed PR.

    # update-PR.ps1
    
    $organization = "organization name"
    $project = "project name"
    $repositoryName = "repository name"
    $pullRequestId = 71
    $newTtitle = "new title of PR"
    $pat = "Personal Access Token"
    
    $uri = "https://dev.azure.com/${organization}/${project}/_apis/git/repositories/${repositoryName}/pullrequests/${pullRequestId}?api-version=7.0"
    
    $base64AuthToken = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))
    $headers = @{
        Authorization = "Basic $base64AuthToken"
        "Content-Type" = "application/json"
    }
    
    $body = @{title = $newTtitle} | ConvertTo-Json -Depth 5
    
    $updatePR = Invoke-RestMethod -Method PATCH -Uri $uri -Body $body -Headers $headers
    Write-Host ($updatePR | ConvertTo-Json -Depth 10)
    

    It returns the following error message.

    TF401181: The pull request cannot be edited due to its state. enter image description here