我正在尝试使用比我目前所做的更好的方法列出尚未完成并转移到当前 sprint 的用户故事。输出应该列出不是在当前 sprint 迭代中创建的用户故事,并且它必须在要列出的任何先前迭代中至少被激活一次。我的输出是正确的,但问题是我必须手动更改日期,因为我使用了创建日期字段,并且手动将其设置为大于我当前 sprint 迭代的开始日期。是否有另一种方法可以检测用户故事是否曾经在之前的 sprint 迭代中,以便我可以列出它们是否被转移到当前的 sprint?我正在考虑比较故事的创建日期,以便不会列出新故事,但我没有找到正确的参数。
问问题
3471 次
2 回答
1
我们无法通过内置的工作项查询来实现这一点,但是我们可以通过在脚本中调用 REST API 来实现这一点(Wiql - Query By Wiql和Revisions - Get)。
请尝试以下适用于我的 PowerShell 脚本:(您也可以将列表导出为 CSV 文件,然后使用 Microsoft Excel 打开)
它从特定团队的当前迭代中查询未完成User Story
,然后检索每个团队的工作项修订以检测System.IterationPath
字段以获取所有值。如果该字段具有多个唯一值,则意味着工作项从先前的迭代携带到当前的 sprint 迭代:
Param(
[string]$baseurl = "https://dev.azure.com/{organization}",
[string]$projectName = "project name",
[string]$user = "username",
[string]$token = "password/PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
# Query the work items with wiql
$uri = "$baseurl/$($projectName)/_apis/wit/wiql?api-version=5.1"
function CreateJsonBody
{
$value = @"
{
"query": "Select [System.Id], [System.Title], [System.State],[System.Tags] From WorkItems Where [System.WorkItemType] = 'User Story' AND [System.State] <> 'Closed' AND [System.State] <> 'Removed' AND [System.IterationPath] = @currentIteration('[Agile-0219]\Agile-0219 Team') order by [System.CreatedDate] desc"
}
"@
return $value
}
$json = CreateJsonBody
#Get the urls for WIs
$queryresult = Invoke-RestMethod -Uri $uri -Method POST -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$wiurls = $queryresult.workItems.url
#Filter the work items which carried from other iterations to current iteration
$wis = @()
cls
foreach($wiurl in $wiurls){
#Set the work item revision URL
$revurl = "$wiurl/revisions"
$wi = (Invoke-RestMethod -Uri $revurl -Method GET -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
#Detect the Unique iterations which the work item ever been involved
$iterationcount = ($wi.value.fields.'System.IterationPath'|select -Unique).count
#write-host $iterationcount
if ($iterationcount -gt 1) # Filter the work items which moved from other iterations
{
# Select the latest revision
$wilatest = ($wi.value | Select -last 1)
$customObject = new-object PSObject -property @{
"WitID" = $wilatest.id
"Title" = $wilatest.fields.'System.Title'
"AssignedTo" = $wilatest.fields.'System.AssignedTo'.displayName
"ChangedDate" = $wilatest.fields.'System.ChangedDate'
"ChangedBy" = $wilatest.fields.'System.ChangedBy'.displayName
"WorkItemType" = $wilatest.fields.'System.WorkItemType'
"State" = $wilatest.fields.'System.State'
"URL" = $wilatest.url
}
$wis += $customObject
}
}
$wis | Select-Object `
WitID,
Title,
AssignedTo,
ChangedDate,
ChangedBy,
WorkItemType,
State,
URL #|export-csv -Path D:\sample.csv -NoTypeInformation
更新
如果要在查询中按创建日期进行过滤,则只需添加过滤条件,例如:AND [System.CreatedDate] < '2019-10-10'
所以,查询应该是:
"Select [System.Id], [System.Title], [System.State],[System.Tags] From WorkItems Where [System.WorkItemType] = 'User Story' AND [System.State] <> 'Closed' AND [System.State] <> 'Removed' AND [System.IterationPath] = @currentIteration AND [System.CreatedDate] < '2019-10-10' order by [System.CreatedDate] desc"
于 2019-12-27T13:22:40.917 回答
0
我想,你用最好的方法。您可以添加日期宏(如 @StartOfWeek-1),以帮助分析您的用户故事,而无需更改查询中的日期(基于日期、周、月或年的查询)。此外,您可以使用 Power BI 报告,您可以在其中分析工作项的每个历史修订并查找以前的迭代。使用 Power BI 数据连接器连接到分析
于 2019-12-27T09:13:28.387 回答