Closed DanielSSilva closed 3 years ago
After a long time of debugging, I've found the issue and a solution. Update-VSTeamPullRequest performs a PATCH request, where only the property being changed is sent. This is true for most cases, but it seems that when the status is "completed", it's different. Making the request on the Azure DevOps website, and using the developer console, I've found that the "complete" is a PATCH request that sends the status (so far, so good) but also requires a "lastMergeSourceCommit" object
I was able to modify the vsteam.functions.ps1
to include this object.
####### current code ##########
# if ($Status) {
# $body = '{"status": "' + $Status + '"}'
# }
####### my change #########
if ($Status) {
if($Status -eq "completed")
{
$lastMergeSourceCommit = Get-VSTeamPullRequest -RepositoryId $RepositoryId | Where-Object {$_.pullRequestId -eq $PullRequestId} | Select-Object -ExpandProperty lastMergeSourceCommit | ConvertTo-Json
$body = '{"status": "' + $Status + '", "lastMergeSourceCommit": ' + $lastMergeSourceCommit + '}'
$body
}
else{
$body = '{"status": "' + $Status + '"}'
}
}
Essentially my workaround was to fetch the lastMergeSourceCommit
from the PR that is being requested to change, convert it to json and append to the body.
Here's the execution result (I've printed the body for debugging)
And here's the "proof" on DevOps
I would love to contribute to this and submit a PR. I will try to understand how can I do so, but any pointers are welcome :)
Steps to reproduce
Expected behavior
Actual behavior
Environment data
OS
Server
Note: I can abandon a PR, but I cannot mark it as "completed". I've tried to look for the "LastMergeSourceCommit " parameter on the source code, but can't find anything related to that that can be filled from my side