【问题标题】:TFS How to get links from work item id using REST apiTFS 如何使用 REST api 从工作项 id 获取链接
【发布时间】:2018-11-16 15:06:03
【问题描述】:

我正在尝试使用休息 API 在给定工作项 ID 的情况下获取 TFS 中的链接列表。 我想过滤掉链接,以便我只有提交。我将使用什么格式的 Web 请求? 我试过了

https://{server & port}/{project}/_workitems?id=140464

但无济于事 - 它把我带到了“分配”给我的查询区域 我也一直在 URL 中省略 API-version=4.1,因为由于某种原因这不起作用...

另外,我尝试在查询中查找工作项,但关于链接的有用信息很少。我至少需要链接的标题,但只有方法可以查看其类型

Commit in Links

【问题讨论】:

  • 您调用的实际 REST API URI 是什么?你怎么称呼它?这看起来不像 REST API。 REST API 都在_api 位置下路由。您是否查看过关于 TFS 中可用的 REST API 的相当广泛的文档?
  • @DanielMann VSTS 提供的 REST API

标签: rest tfs hyperlink tfs-workitem workitem


【解决方案1】:

您可以通过以下REST API 检索特定工作项的所有关系(链接的工作项):

GET http://server:8080/tfs/DefaultCollection/_apis/wit/workitems/1?$expand=all 

然后您可以在循环中为每个链接的工作项获取ID type title

只需尝试以下 PowerShell 示例,即可使用 REST API 获取链接信息:

Param(
   [string]$collectionurl = "http://server:8080/tfs/DefaultCollection",
   [string]$workitemid = "1",
   [string]$user = "username",
   [string]$token = "password"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

#Get workitem relateions
$baseUrl = "$collectionurl/_apis/wit/workitems/$($workitemid)?"+"$"+"expand=all"            
$response = Invoke-RestMethod -Uri $baseUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

$witurls = $response.relations.url 

#Retrieve the linked work items in a loop
$linkedwits = @()

foreach ($witurl in $witurls)
{
$linkedwit = Invoke-RestMethod -Uri $witurl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

$customObject = new-object PSObject -property @{
          "LinkedWitID" = $linkedwit.id
          "WorkItemType" = $linkedwit.fields.'System.WorkItemType'
          "Title" = $linkedwit.fields.'System.Title'
        } 

    $linkedwits += $customObject
}

$linkedwits | Select `
                LinkedWitID,
                WorkItemType, 
                Title #|export-csv -Path C:\LC\Links.csv -NoTypeInformation

【讨论】:

  • @Zealia 您是否通过答案解决了问题?任何更新? ——
猜你喜欢
  • 2017-05-07
  • 2019-03-11
  • 1970-01-01
  • 2019-02-06
  • 2017-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-31
相关资源
最近更新 更多