gpt4 book ai didi

rest - 通过 REST API 列出 VSTS 工作项列表

转载 作者:行者123 更新时间:2023-12-03 23:31:09 24 4
gpt4 key购买 nike

如何使用 REST API 从 VSTS 获取工作项列表?

根据documentation , ids 参数是可选的,但是当我省略它时,我得到一个 404 错误。如果我添加 ids 参数,我可以获取项目。

请求失败:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?api-version=1.0

成功的请求:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?ids=252&api-version=1.0

两者的身份验证相同。

要解决的完整问题是:获取特定 VSTS 项目中的所有功能

最佳答案

关键是使用 API 的 WIQL 部分,而不是工作项之一。例如,要获取某种类型的工作项的平面列表,请使用以下命令: https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#a-flat-query

PowerShell 中的示例(显示所有处于关闭状态的用户故事):

    # using env vars passed from VSTS build
$collectionuri = $Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI
$token = $Env:SYSTEM_ACCESSTOKEN # need to configure build to allow passing OAuth tokens

$basicAuth = "{0}:{1}"-f "ivan-the-terrible", $token
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=("Basic {0}"-f $basicAuth)}

$WorkItemType = 'User Story'

$url = $collectionuri + 'DefaultCollection/_apis/wit/wiql?api-version=1.0'

$WIQL_query = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = '" + $WorkItemType + "' AND [State] = 'Closed' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
$body = @{ query = $WIQL_query }
$bodyJson=@($body) | ConvertTo-Json

$response = Invoke-RestMethod -Uri $url -headers $headers -Method Post -ContentType "application/json" -Body $bodyJson

$workitems = $response.workItems

Write-Host "Found" $workitems.Count "work items of type:" $WorkItemType

关于rest - 通过 REST API 列出 VSTS 工作项列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39034029/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com