3
votes

The documentation says that the TargetRefName can be updated when "PR retargeting feature is enabled" but I can't find this option anywhere and can't see any documentation about how to enable it either.

How do I enable PR retargeting so that I can update the PR's target?

https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/update?view=azure-devops-rest-5.1

2

2 Answers

1
votes

I succeded to update the target branch with the API you provided with the following body:

{"targetRefName":"refs/heads/test"}

In PowerShell:

$pat = "YOUR-PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,"$pat")))
$headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}

$url = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=5.1"

$json = '{"targetRefName":"refs/heads/master"}'

$response = Invoke-RestMethod -Uri $url -Method PATCH -ContentType application/json -Headers $headers -Body $json

It look like each PR could be re-targeted, I don't see an option enable/disable the feature.

By the way, I succeeded only in the above JSON, if you will try to get the PR and change the targetRefName you will get an error.

3
votes

see this image

Click on the more action button(...) and you will see "Change target branch"