Home > Blockchain >  Is it possible to add comment as 'resolved' to PR in Azure DevOps?
Is it possible to add comment as 'resolved' to PR in Azure DevOps?

Time:09-20

We are using Azure DevOps Pipeline, as part of the pipeline we are adding a comment to the PR via REST API. We'd like this comment to be marked as 'resolved' automatically (instead of active), can this be done? I didn't find anything on Azure DevOps REST API documentation.

Here is the script we are using to add the comment:

$StatusCode = 1 

$Stuff = $env:newVersion
$Things = "$($env:System_TeamFoundationCollectionUri)$($env:System_TeamProject)/_apis/build/builds/$($env:Build_BuildId)/artifacts?artifactName=PM_$($env:newVersion)&$format=zip"

#Build Up a Markdown Message to 
$Markdown = @"
|Version |Download Link|
|--------|---------|
|$Stuff|$Things|  
"@

#Build the JSON body up
$body = @"
{
    "comments": [
      {
        "parentCommentId": 0,
        "content": "$Markdown",
        "commentType": 1
      }
    ],
    "status": $StatusCode 
  }
"@

Write-Debug $Body
#Post the message to the Pull Request
#https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull request threads?view=azure-devops-rest-5.1
try {
    $url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/git/repositories/$($env:Build_Repository_Name)/pullRequests/$($env:System_PullRequest_PullRequestId)/threads?api-version=5.1"
    Write-Host "URL: $url"
    $response = Invoke-RestMethod -Uri $url -Method POST -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Body $Body -ContentType application/json
  if ($response -ne $Null) {
    Write-Host "*******************Bingo*********************************"
  }
}
catch {
  Write-Error $_
  Write-Error $_.Exception.Message
}

CodePudding user response:

Use Fixed status:

$body = @"
{
"comments": [
      {
        "parentCommentId": 0,
        "content": "New resolved comment",
        "commentType": 1
      }
    ],
    "status": "Fixed" 
}
"@

Supported statuses: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-request-threads/create?view=azure-devops-rest-7.1&tabs=HTTP#commentthreadstatus

  • Related