通过 REST 获取工作项的父级 API
Getting parent of work item through REST API
我们正在开发 Azure DevOps 扩展以将对工作项的更改推送到外部系统。
我们想要 maintain/preserve 目标系统中 Azure DevOps 中的层次结构(Epic-> Feature -> PBI/Bug),因此我们需要弄清楚工作项有哪个父项。
当从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" 的引用痕迹。
难道这个值没有暴露是真的吗?
您可以通过将 $expand=relations
添加到 api 字符串来获取所有工作项链接(父项、子项等)。
例如:
https://shaykia.visualstudio.com/_apis/wit/workItems/4?$expand=relations
在结果中您将看到 "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
用于子级。
我们正在开发 Azure DevOps 扩展以将对工作项的更改推送到外部系统。
我们想要 maintain/preserve 目标系统中 Azure DevOps 中的层次结构(Epic-> Feature -> PBI/Bug),因此我们需要弄清楚工作项有哪个父项。
当从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" 的引用痕迹。
难道这个值没有暴露是真的吗?
您可以通过将 $expand=relations
添加到 api 字符串来获取所有工作项链接(父项、子项等)。
例如:
https://shaykia.visualstudio.com/_apis/wit/workItems/4?$expand=relations
在结果中您将看到 "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
用于子级。