通过REST API获取工作项的父级

16
我们正在开发一个Azure DevOps扩展程序,将工作项更改推送到外部系统。
我们希望在目标系统中维护/保留Azure DevOps中的层次结构(史诗->特性->产品待办项/缺陷),因此我们需要确定工作项的父项。
从API中提取工作项实体时,它看起来像这样(有点简略)。
{
    "id": 5202,
    "rev": 2,
    "fields": {
        "System.WorkItemType": "Task",
        "System.State": "To Do",
        "System.Reason": "New task",
        "System.CreatedDate": "2017-10-30T10:18:06.233Z",
        "System.CreatedBy": "Jesper Lund Stocholm",
        "Microsoft.VSTS.Common.Priority": 2,
        "Microsoft.VSTS.Scheduling.RemainingWork": 23.0,
        "Microsoft.VSTS.Common.StateChangeDate": "2017-10-30T10:18:06.233Z",
    },
    "_links": {
            "self": {
            "href": "https://{myorg}.visualstudio.com/_apis/wit/workItems/5202"
        },
        "workItemUpdates": {
            "href": "https://{myorg}.visualstudio.com/_apis/wit/workItems/5202/updates"
        },
        "workItemRevisions": {
            "href": "https://{myorg}.visualstudio.com/_apis/wit/workItems/5202/revisions"
        },
        "workItemHistory": {
            "href": "https://{myorg}.visualstudio.com/_apis/wit/workItems/5202/history"
        },
        "html": {
            "href": "https://{myorg}.visualstudio.com/web/wi.aspx?pcguid=e5d991b2-9879-497c-85fb-c618f144a9c5&id=5202"
        },
        "workItemType": {
            "href": "https://{myorg}.visualstudio.com/6847ebed-cbca-4510-8baa-228c7c55ba8d/_apis/wit/workItemTypes/Task"
        },
        "fields": {
            "href": "https://{myorg}.visualstudio.com/_apis/wit/fields"
        }
    },
    "url": "https://{myorg}.visualstudio.com/_apis/wit/workItems/5202"
}

显然,最好的查找位置在这里 https://{myorg}.visualstudio.com/_apis/wit/fields

但是我们没有找到任何关于“parent entity”的引用痕迹。

这个值真的没有被公开吗?

1个回答

32

通过在API字符串中添加$expand=relations,您可以获取所有工作项链接(父级、子级等)。

例如:

https://shaykia.visualstudio.com/_apis/wit/workItems/4?$expand=relations
在结果中,您将看到“关系”部分:
"relations": [
    {
      "rel": "System.LinkTypes.Hierarchy-Forward",
      "url": "http:/shaykia.visualstudio.com/_apis/wit/workItems/11",
      "attributes": {
        "isLocked": false
      }
    },
    {
      "rel": "System.LinkTypes.Hierarchy-Reverse",
      "url": "http://shaykia.visualstudio.com/_apis/wit/workItems/3",
      "attributes": {
        "isLocked": false
      }
    }
  ], 

System.LinkTypes.Hierarchy-Reverse 是用于表示父级 (在这种情况下,具有 ID 3 的工作项是父级),而 System.LinkTypes.Hierarchy-Forward 则是用于表示子级。


谢谢您,@shayki! - Jesper Lund Stocholm
1
@shayki 我该如何筛选只有特定属性的关系? - Andreas
1
@Andreas 我不认为你可以在URL中过滤,你需要过滤结果。 - Shayki Abramczyk
1
文档中有 ?$expand=relations 吗?我找不到它。 - Jake12342134

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接