【问题标题】:Azure DevOps - query which user "Changed state from 'x' to 'y'Azure DevOps - 查询哪个用户“将状态从'x'更改为'y'
【发布时间】:2020-11-27 17:35:01
【问题描述】:

是否可以在 Azure DevOps 中运行查询以匹配“user” = 'Bob' “Changed State from” 'x' to 'y'?

我们在看板中工作,因此状态由用户从设计更改为开发。我想找到该用户从设计更改为开发的任何项目。

请帮忙!

【问题讨论】:

    标签: azure-devops


    【解决方案1】:

    恐怕你需要调用rest api来获取这些工作项。

    1. 使用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]" }'

    2. 使用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 输出到控制台。

    【讨论】:

    • 谢谢@Levi Lu-MSFT,这确实帮助我看到了变化,但没有给出从设计到开发的转变。有什么想法吗?再次感谢您的宝贵时间。
    • 恐怕您无法使用Query查询这些工作项。您将需要使用 rest api 来实现这一点。见上文已更新。
    猜你喜欢
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多