导出 Azure DevOps 中每个工作项的最新讨论帖子

问题描述

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

第 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,然后可以用它来查找讨论信息 - 正如我在查找讨论评论、发布日期、个人发布名称之前提到的那样,并且这只是每个工作项目的最新讨论帖子,但不知道这是否可能或如何完成。有人可以提供有关第 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 返回工作项评论列表。如果只想获取最新评论,请添加 $top 参数:

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...