Skip to content

Instantly share code, notes, and snippets.

@ransagy
Created March 17, 2022 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ransagy/e62d5505770125d32a1c57670972a874 to your computer and use it in GitHub Desktop.
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
# 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 {
$_
}
@zioalex
Copy link

zioalex commented Jun 24, 2022

@ransagy
Copy link
Author

ransagy commented Jun 25, 2022

Yup, Thanks for filling it in :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment