azure-devops - 通过REST API获取工作项的父项

标签 azure-devops azure-devops-rest-api azure-devops-extensions

我们正在开发Azure DevOps扩展,以将对工作项的更改推送到外部系统。

我们希望在目标系统的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

但是我们找不到对“父实体”的引用的任何痕迹。

可以不公开此值吗?

最佳答案

您可以通过将$expand=relations添加到api字符串来获取所有工作项链接( parent , child 等)。

例如:

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适用于父级(在这种情况下,标识为3的工作项他是父级),而System.LinkTypes.Hierarchy-Forward适用于子级。

关于azure-devops - 通过REST API获取工作项的父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52293764/

相关文章:

azure-devops - 如何使用 Rest API 在测试用例工作项中添加测试步骤

tfs - Devops 自定义规则以增加字段

azure - 是否可以使用 PowerShell 脚本创建 Azure Databricks 集群?

azure - 使用 VSTS 的 ASP.NET Core Web API 的 CI/CD

powershell - 抛出了 'Microsoft.Rest.Azure.CloudException' 类型的异常

azure - 在 Azure DevOps 中通过拉取请求进行构建

azure-devops-rest-api - 使用 REST API 将构建链接添加到工作项

azure-devops - 创建一个自动 PR 并完成它 Azure DevOps

laravel - "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"Azure 上的 Laravel