Reputation: 9836
I'm trying to post a comment on a PR using the Azure API in Powershell.
I've found this resource: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull%20request%20thread%20comments/create?view=azure-devops-rest-5.0
And I've implemented it:
$postURL = "https://dev.azure.com/$organization/$project/_apis/git/repositories/$repositoryId/pullRequests/$pullRequestId/threads/$threadId/comments?api-version=5.0"
$prComment = Invoke-RestMethod -Uri $postURL -Headers @{Authorization = $pat} -Body $body
When I run this with $threadId = 1
I get:
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"The requested> pull request comment thread '1' cannot be found.
When I run it with $threadId = 0
I get:
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"The value 0 is outside of the allowed range
This is a image of the comment section of the pull request with id 1:
So what is the thread id
of a PR?
Upvotes: 0
Views: 1203
Reputation: 9836
I figured out by using the API:
https://dev.azure.com/$organization/$project/_apis/git/repositories/$repositoryId/pullRequests/$pullRequestId/threads?api-version=5.0
You can get a list of threads for that PR. Each line in the comment section represents a thread. And where I thought that thread id is linked to the PR (ie. created by PB
is thread id 1 inside that PR), it is not. Each new thread increments the thread id. So if I add a thread in a different PR it could have thread id 231
. If I add another thread in a different PR it will have id 232
. Which is quite annoying. I can't understand why Azure would implement it this way.
Upvotes: 1