我正在尝试使用Powershell中的Azure API在PR上发表评论。
我已经实现了:
$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
当我用$threadId = 1
运行时,我得到:
Invoke-RestMethod:{“ $ id”:“ 1”,“ innerException”:null,“ message”:“找不到所请求的请求请求注释线程'1'。
当我使用$threadId = 0
运行它时,我得到:
Invoke-RestMethod:{“ $ id”:“ 1”,“ innerException”:null,“ message”:“值0超出允许范围
这是ID为1的拉取请求的注释部分的图像:
那么PR的thread id
是什么?
答案 0 :(得分:0)
我通过使用API找出了答案:
https://dev.azure.com/$organization/$project/_apis/git/repositories/$repositoryId/pullRequests/$pullRequestId/threads?api-version=5.0
您可以获取该PR的线程列表。注释部分中的每一行代表一个线程。在我认为线程ID链接到PR的地方(即created by PB
是该PR内的线程ID 1),却不是。每个新线程都会增加线程ID。因此,如果我在其他PR中添加线程,则其线程ID为231
。如果我在另一个PR中添加另一个线程,它将具有ID 232
。这很烦人。我不明白为什么Azure会以这种方式实现它。