首页 > 解决方案 > 如何找到 Azure 拉取请求的 threadID?

问题描述

我正在尝试使用 Powershell 中的 Azure API 对 PR 发表评论。

我找到了这个资源:https ://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20request%20thread%20comments/create?view=azure-devops-rest-5.0

我已经实现了它:

$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":"The requested> pull request comment thread '1' 找不到。

当我运行它时,$threadId = 0我得到:

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"值 0 超出允许范围

这是 ID 为 1 的拉取请求的评论部分的图像:

在此处输入图像描述

那么什么是thread idPR?

标签: azureazure-devops

解决方案


我通过使用 API 发现:

https://dev.azure.com/$organization/$project/_apis/git/repositories/$repositoryId/pullRequests/$pullRequestId/threads?api-version=5.0

您可以获得该 PR 的线程列表。评论部分的每一行代表一个线程。我认为线程 id 与 PR 相关联(即,该 PRcreated by PB内的线程 id 为 1),但事实并非如此。每个新线程都会增加线程 ID。因此,如果我在不同的 PR 中添加一个线程,它可能有线程 id 231。如果我在不同的 PR 中添加另一个线程,它将具有 id 232。这很烦人。我不明白为什么 Azure 会以这种方式实现它。


推荐阅读