Created
March 17, 2022 09:17
-
-
Save ransagy/e62d5505770125d32a1c57670972a874 to your computer and use it in GitHub Desktop.
Example of adding a comment to a pull request in Azure Devops using the REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# status 4 = closed | |
$Body = @" | |
{ | |
"comments": [ | |
{ | |
"parentCommentId": 0, | |
"content": "Just ye olde comment added and marked as closed..", | |
"commentType": 1 | |
} | |
], | |
"status": 4 | |
} | |
"@ | |
# This token came from an Azure Devops pipeline, use whatever auth you need elsewhere. | |
$Headers = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" } | |
try { | |
# Similary to above, these were taken from a pipeline, denoting repo details. fill in as needed. | |
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/git/repositories/$($env:BUILD_REPOSITORY_NAME)/pullRequests/$($env:BUILD_PULLREQUEST_ID)/threads?api-version=6.0" | |
$response = Invoke-RestMethod -Uri $url -Method POST -Headers $Headers -Body $Body -ContentType application/json | |
if ($Null -ne $response) { | |
Write-Host "Added deploy complete comment on the pull request." | |
} | |
} | |
catch { | |
$_ | |
} |
Yup, Thanks for filling it in :]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing it. The original doc can be useful here: https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull-request-threads?view=azure-devops-rest-6.0