TFS如何使用REST API从工作项ID获取链接 [英] TFS How to get links from work item id using REST api

查看:232
本文介绍了TFS如何使用REST API从工作项ID获取链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用rest API在给定工作项ID的情况下获取TFS中的链接列表. 我想过滤掉链接,以便仅提交.我将使用哪种格式的Web请求? 我已经尝试过

I'm trying to get the list of links in TFS given the work item ID using a rest API. I want to filter out the links so that I only have the commits. What format for a web request would I use? I've tried

https://{服务器& port}/{project}/_ workitems?id = 140464

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

但无济于事-它使我进入已分配"给我的查询区域 我也从URL中省略了API-version = 4.1,因为某些原因,它不起作用...

but to no avail - It brings me to the 'assigned' to me query area I have also been omitting API-version=4.1 from the URL because for some reason that doesn't work...

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

Also, I tried looking up the work item in a query but there is little helpful information about the links. I need at least the link's title, but there are only methods to see its type

提交链接

推荐答案

您可以通过下面的然后,您可以在循环中为每个链接的工作项获得ID type title.

Then you can get the ID type title for each of the linked work items in a loop.

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

Just try below PowerShell sample to get the links' information with the 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

这篇关于TFS如何使用REST API从工作项ID获取链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆