为 Azure DevOps 中的每个工作项导出最新讨论 post

Export latest discussion post for each and every work item in Azure DevOps

我希望在 DevOps 中为每个工作项目带回最新的讨论 post,以及留下评论的人的姓名(或他们的电子邮件地址)和他们离开的日期评论。我正在做的项目在过去的几周里有各种各样的人来来去去,在大多数情况下并没有真正的交接。

第 1 步我想我已经根据此处的类似问题进行了介绍...

$token = "PAT"

$url="https://dev.azure.com/{Org}/_apis/wit/wiql?api-version=5.1"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$JSON = @'
{
   "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType]  <> ''"
}
'@

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json


ForEach( $workitemid in $response.workItems.id ) 
{

echo $workitemid

???

如果我是对的,这个代码片段实质上是在发挥作用,然后可以用来查找讨论信息的工作项 ID - 如前所述,我正在寻找讨论评论,日期 post ed,个人姓名 posting,这只是每个工作项目的最新讨论 post,但不知道这是否可能或如何完成。谁能就第 2 步提供一些指导?

它看起来不是可以在 DevOps 本身中查询的东西,但假设它是可以以某种方式浮出水面的信息?

您可以使用 Rest Api Comments:

$token = "<pat>"

$urlQueryItems="https://dev.azure.com/<org>/_apis/wit/wiql?api-version=5.1"
$urlWorkItemTemplate="https://dev.azure.com/<org>/_apis/wit/workItems/{workItemId}?api-version=5.1"
$urlGetCommentsTemplate = "https://dev.azure.com/<org>/{projectName}/_apis/wit/workItems/{workItemId}/comments?api-version=5.1-preview.3 "

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$JSON = @'
{
   "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType]  <> ''"
}
'@

$queryResponse = Invoke-RestMethod -Uri $urlQueryItems -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json


ForEach( $workitemid in $response.workItems.id ) 
{
    $urlWorkItem = $urlWorkItemTemplate -replace "{workItemId}", $workitemid

    $workItemResponse = Invoke-RestMethod -Uri $urlWorkItem -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json

    $urlGetComments = $urlGetCommentsTemplate -replace "{workItemId}", $workitemid

    $urlGetComments = $urlGetComments -replace "{projectName}", $workItemResponse.fields.'System.TeamProject'
    
    $commentsResponse = Invoke-RestMethod -Uri $urlGetComments -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json

    foreach($comment in $commentsResponse.comments)
    {
        echo $comment.createdDate $comment.createdBy.displayName $comment.text
    }
}

Comments - Get Comments api returns 工作项注释列表。如果只想获取最新评论,添加$top参数:

GET https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/{workItemId}/comments?$top=1&api-version=6.0-preview.3

您可以从响应中获取评论文本、createdBy、createdDate 等。