【问题标题】:Export latest discussion post for each and every work item in Azure DevOps导出 Azure DevOps 中每个工作项的最新讨论帖子
【发布时间】:2021-02-23 01:54:38
【问题描述】:

我希望为每个工作项返回 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

???

如果我是对的,这个 sn-p 本质上是在发挥工作项 id 的作用,然后可以使用它来查找讨论信息 - 如前所述,我正在寻找讨论评论、发布日期、个人姓名发布,并且这只是每个工作项的最新讨论帖子,但不知道这是否可能或如何完成。任何人都可以提供有关第 2 步的一些指导吗?

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

【问题讨论】:

  • 你检查过以下回复吗?你的问题解决了吗?

标签: powershell azure-devops workitem azure-boards


【解决方案1】:

你可以使用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
    }
}

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

    • 复制我的答案有什么意义?
    猜你喜欢
    • 2022-09-27
    • 1970-01-01
    • 2019-12-17
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多