-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new cmdlet for querying workitems by WIQL
- Loading branch information
1 parent
1d18f39
commit 64bc1dd
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SebastianSchuetze
Author
Collaborator
|
||
} | ||
|
||
} | ||
|
||
_applyTypesToWiql -item $resp | ||
|
||
return $resp | ||
} | ||
} |
If I may give a hint to this code
I would avoid '+=' because of performance.
Like this:
Resp.workItems = for ($begin...
...
(Get-VSTeamWorkItem -Fields $Fields -Id's $idArray).value
}