gpt4 book ai didi

azure-devops - Azure Devops Rest Api 获取团队当前 Sprint 的工作项和任务

转载 作者:行者123 更新时间:2023-12-04 12:38:57 44 4
gpt4 key购买 nike

我正在寻找构建一些工具来查询团队的 sprint 当前工作项。鉴于组织、项目和团队,我不确定如何做到这一点。我似乎可以通过拨打这个电话获得当前的迭代:

https://dev.azure.com/ {org}/{project}/{{team}/_apis/work/teamsettings/iterations?$timeframe=current&api-version=5.1

它返回如下内容:

 {
"count": 1,
"value": [
{
"id": "8c15e886-ece7-49ce-ab5a-4090aefb5ce2",
"name": "Sprint 1",
"path": "Red Kitten Matrix\\Sprint 1",
"attributes": {
"startDate": null,
"finishDate": null,
"timeFrame": "current"
},
"url": "https://dev.azure.com/chrisdevopsprojects/e8d05711-3014-4ba7-82b7-ab6829c455dc/aed68f47-9035-4af5-9b0d-b0c19b4e9e9e/_apis/work/teamsettings/iterations/8c15e886-ece7-49ce-ab5a-4090aefb5ce2"
}
]
}

因此,我可以获得当前团队的 sprint 的指针,但是如何返回所有 sprints 工作项和其中的任务?

我在这里没有看到任何信息:

https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/list?view=azure-devops-rest-5.1

谢谢!

编辑:

所以我发现了一个工作项查询语言(WIQL...原因为什么不猜测)查询,当我在 UI 中的 devops 中调用它时它可以工作,并且可以通过其余的 API 工作,但它会导致我做一个一堆 ajax 请求将所有东西拉回来。请让我知道是否有更简单的方法来获得它。

这是我的 WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State],
[System.Tags]
FROM workitemLinks
WHERE
(
[Source].[System.TeamProject] = @project
AND [Source].[System.WorkItemType] <> 'Task'
AND [Source].[System.State] <> ''
AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\Red Kitten Matrix Team <id:aed68f47-9035-4af5-9b0d-b0c19b4e9e9e>')
)
AND (
[Target].[System.TeamProject] = @project
AND [Target].[System.WorkItemType] <> ''
)
ORDER BY [System.Id]
MODE (MayContain)

它在 UI 中返回这个漂亮的结果:
enter image description here

但是,当我尝试通过此端点通过 apis 执行此操作时:
https://dev.azure.com/chrisdevopsprojects/Red%20Kitten%20Matrix/Red%20Kitten%20Matrix%20Team/_apis/wit/wiql?api-version=5.1

发布这个机构:
{
"query": "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM workitemLinks WHERE ( [Source].[System.TeamProject] = @project AND [Source].[System.WorkItemType] <> 'Task' AND [Source].[System.State] <> '' AND [Source].[System.IterationPath] = @currentIteration('[Red Kitten Matrix]\\Red Kitten Matrix Team')) AND ([Target].[System.TeamProject] = @project AND [Target].[System.WorkItemType] <> '' ) ORDER BY [System.Id] MODE (MayContain)"
}

我得到这样的响应:
{
"queryType": "oneHop",
"queryResultType": "workItemLink",
"asOf": "2020-04-28T03:00:48.353Z",
"columns": [
{
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
{
"referenceName": "System.WorkItemType",
"name": "Work Item Type",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.WorkItemType"
},
{
"referenceName": "System.Title",
"name": "Title",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Title"
},
{
"referenceName": "System.AssignedTo",
"name": "Assigned To",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.AssignedTo"
},
{
"referenceName": "System.State",
"name": "State",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.State"
},
{
"referenceName": "System.Tags",
"name": "Tags",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Tags"
}
],
"sortColumns": [
{
"field": {
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
"descending": false
},
{
"field": {
"referenceName": "System.Id",
"name": "ID",
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/fields/System.Id"
},
"descending": false
}
],
"workItemRelations": [
{
"rel": null,
"source": null,
"target": {
"id": 6,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
}
},
{
"rel": "System.LinkTypes.Hierarchy-Forward",
"source": {
"id": 6,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/6"
},
"target": {
"id": 10,
"url": "https://dev.azure.com/chrisdevopsprojects/_apis/wit/workItems/10"
}
},
...

所以看起来它没有返回我在我的 WIQL 中指定的列,我将不得不转过身来查询从这个查询返回的每个工作项 id 的工作项 api。我想避免进行 20 多个休息调用来解析我想要的数据。有没有更好的方法?

谢谢

最佳答案

您可以使用 OData API查询工作项数据。 https://analytics.dev.azure.com/{OrganizationName}/{ProjectName}/_odata/{version}
对于powershell脚本中的以下示例:

$ourl = "https://analytics.dev.azure.com/{AzureOrganizationName}/{ProjectName}/_odata/v3.0-preview/WorkItems?`$filter=Iteration/IterationPath eq 'iterationName\iteration 5' and WorkItemType ne 'Task'&`$expand=Children(`$filter=WorkItemType ne '')&`$select=WorkItemId, Title, State" 

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

$result = Invoke-RestMethod -Uri $ourl -Method Get -Header @{Authorization = "Basic $base64AuthInfo"}
$result.value

您可以从下面的返回结果中看到,返回了所需的工作项列。

enter image description here

查看文档 Query for linked work items 中的示例查询链接的工作项。

希望以上有帮助!

关于azure-devops - Azure Devops Rest Api 获取团队当前 Sprint 的工作项和任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61469326/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com