From 64bc1dd1e05321e3805936f2e629f78f2c551b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 3 Oct 2019 03:25:00 +0200 Subject: [PATCH] added new cmdlet for querying workitems by WIQL --- Source/Public/Get-VSTeamWiql.ps1 | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Source/Public/Get-VSTeamWiql.ps1 diff --git a/Source/Public/Get-VSTeamWiql.ps1 b/Source/Public/Get-VSTeamWiql.ps1 new file mode 100644 index 000000000..045e032ad --- /dev/null +++ b/Source/Public/Get-VSTeamWiql.ps1 @@ -0,0 +1,82 @@ +function Get-VSTeamWiql { + [CmdletBinding(DefaultParameterSetName = 'ByID')] + param( + [Parameter(ParameterSetName = 'ByID', Mandatory = $true, Position = 0)] + [string] $Id, + + [Parameter(ParameterSetName = 'ByQuery', Mandatory = $true, Position = 0)] + [string] $Query, + + [Parameter(Mandatory = $true, Position = 1)] + [string] $Team, + + [int] $Top = 100, + + [Switch] $TimePrecision, + + [Switch] $Expand + ) + DynamicParam { + $arrSet = Get-VSTeamProject | Select-Object -ExpandProperty Name + _buildProjectNameDynamicParam -mandatory $true -arrSet $arrSet + } + + Process { + + # Bind the parameter to a friendly variable + $ProjectName = $PSBoundParameters["ProjectName"] + + $QueryString = @{ + '$top' = $Top + timePrecision = $TimePrecision + } + + # Call the REST API + if ($Query) { + + $body = (@{ + query = $Query + }) | ConvertTo-Json + + $resp = _callAPI -ProjectName $ProjectName -Team $Team -Area 'wit' -Resource 'wiql' ` + -method "POST" -ContentType "application/json" ` + -Version $([VSTeamVersions]::Core) ` + -Querystring $QueryString ` + -Body $body + } + else { + $resp = _callAPI -ProjectName $ProjectName -Team $Team -Area 'wit' -Resource 'wiql' ` + -Version $([VSTeamVersions]::Core) -id "$Id" ` + -Querystring $QueryString + } + + $workItems = @() + if ($Expand) { + + $Ids = $resp.workItems | Select-Object -ExpandProperty id + $Fields = $resp.columns | Select-Object -ExpandProperty referenceName + + $resp.workItems = @() + #splitting id array by 200, since a maximum of 200 ids are allowed per call + $countIds = $Ids.Count + for ($beginRange = 0; $beginRange -lt $countIds; $beginRange += 200) { + + $endRange = ($beginRange + 199) + + if ($endRange -gt $countIds) { + $idArray = $Ids[$beginRange..($countIds - 1)] + } + else { + $idArray = $Ids[$beginRange..($endRange)] + } + + $resp.workItems += (Get-VSTeamWorkItem -Fields $Fields -Ids $idArray).value + } + + } + + _applyTypesToWiql -item $resp + + return $resp + } +} \ No newline at end of file