【发布时间】:2020-11-27 17:35:01
【问题描述】:
是否可以在 Azure DevOps 中运行查询以匹配“user” = 'Bob' “Changed State from” 'x' to 'y'?
我们在看板中工作,因此状态由用户从设计更改为开发。我想找到该用户从设计更改为开发的任何项目。
请帮忙!
【问题讨论】:
标签: azure-devops
是否可以在 Azure DevOps 中运行查询以匹配“user” = 'Bob' “Changed State from” 'x' to 'y'?
我们在看板中工作,因此状态由用户从设计更改为开发。我想找到该用户从设计更改为开发的任何项目。
请帮忙!
【问题讨论】:
标签: azure-devops
恐怕你需要调用rest api来获取这些工作项。
使用WIQL rest api 获取所有工作项。
POST https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=6.1-preview.2
$query='{ "query": "Select [System.Id] From WorkItems Where [System.TeamProject] = @project AND [System.WorkItemType] <> \"\" order by [System.WorkItemType], [System.Id]" }'
使用Updates-List rest api 获取所有更新历史记录并过滤所述用户从设计到开发更改的项目。请参阅下面的 powershell 脚本中的完整示例:
请参阅document 以获取个人访问令牌。
$wurl="https://dev.azure.com/org/proj/_apis/wit/wiql?api-version=6.1-preview.2"
$PersonAcessToken=""
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PersonAcessToken)"))
$query='{
"query": "Select [System.Id] From WorkItems Where [System.TeamProject] = @project AND [System.WorkItemType] <> \"\" order by [System.WorkItemType], [System.Id]"
}'
#call WIQL rest api to get all the work item ids.
$result = Invoke-RestMethod -Uri $wurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/json" -Method post -body $query
$ids = $result.workItems.id
#loop throught all work item to check updates
foreach($id in $ids){
$upurl="https://dev.azure.com/org/proj/_apis/wit/workItems/$id/updates?api-version=6.1-preview.3"
#call Update-list api to get all the historical updates
$response= Invoke-RestMethod -Uri $upurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
$updates = $response.value
foreach($update in $updates){
#Check the items that were changed by said user from Design to Development
if(($update.fields."System.State".newValue -eq "Development") -and ($update.fields."System.State".oldValue -eq "Design") -and ($update.revisedBy.displayName -eq "Bob")){
# output the required workitem's id.
echo $update.workItemId
break
}
}
}
以上脚本将获取 Bob 从设计更改为开发的工作项。并将工作 ID 输出到控制台。
【讨论】: