From af1c7a5a9b6a022514825455b5c107bf768b8a77 Mon Sep 17 00:00:00 2001 From: Michel Zehnder Date: Wed, 19 Feb 2020 15:04:45 +0100 Subject: [PATCH 1/3] Add -Filter, -FilterContains, -Top and -ContinuationToken to Get-VSTeamGitRefs --- CHANGELOG.md | 4 ++ Source/Public/Get-VSTeamGitRef.ps1 | 21 +++++++++- Source/VSTeam.psd1 | 4 +- unit/test/refs.Tests.ps1 | 62 ++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e88b6495..d0db93afa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 6.4.5 + +- Add -Filter, -FilterContains, -Top and -ContinuationToken to Get-VSTeamGitRefs + ## 6.4.4 Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/231) from [Dave Neeley](https://github.com/daveneeley) which included the following: diff --git a/Source/Public/Get-VSTeamGitRef.ps1 b/Source/Public/Get-VSTeamGitRef.ps1 index 256deafe0..b542c2f0e 100644 --- a/Source/Public/Get-VSTeamGitRef.ps1 +++ b/Source/Public/Get-VSTeamGitRef.ps1 @@ -3,7 +3,15 @@ function Get-VSTeamGitRef { param ( [Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)] [Alias('Id')] - [guid] $RepositoryID + [guid] $RepositoryID, + [Parameter()] + [string] $Filter, + [Parameter()] + [string] $FilterContains, + [Parameter()] + [int] $Top, + [Parameter()] + [string] $ContinuationToken ) DynamicParam { @@ -15,7 +23,16 @@ function Get-VSTeamGitRef { $ProjectName = $PSBoundParameters["ProjectName"] try { - $resp = _callAPI -ProjectName $ProjectName -Id "$RepositoryID/refs" -Area git -Resource repositories -Version $([VSTeamVersions]::Git) + + $queryString = @{ + '$top' = $Top + 'filter' = $Filter + 'filterContains' = $FilterContains + 'continuationToken' = $continuationToken + } + + $url = _buildRequestURI -Area git -Resource repositories -Version $([VSTeamVersions]::Git) -ProjectName $ProjectName -Id "$RepositoryID/refs" + $resp = _callAPI -url $url -QueryString $queryString $obj = @() diff --git a/Source/VSTeam.psd1 b/Source/VSTeam.psd1 index 539e9e0d6..65a03ecf5 100644 --- a/Source/VSTeam.psd1 +++ b/Source/VSTeam.psd1 @@ -12,7 +12,7 @@ RootModule = 'VSTeam.psm1' # Version number of this module. - ModuleVersion = '6.4.4' + ModuleVersion = '6.4.5' # Supported PSEditions # CompatiblePSEditions = @() @@ -27,7 +27,7 @@ CompanyName = '' # Copyright statement for this module - Copyright = '(c) 2019 Donovan Brown. All rights reserved.' + Copyright = '(c) 2020 Donovan Brown. All rights reserved.' # Description of the functionality provided by this module Description = 'Adds functionality for working with Azure DevOps and Team Foundation Server.' diff --git a/unit/test/refs.Tests.ps1 b/unit/test/refs.Tests.ps1 index 391a75829..a918fe81f 100644 --- a/unit/test/refs.Tests.ps1 +++ b/unit/test/refs.Tests.ps1 @@ -36,6 +36,68 @@ InModuleScope VSTeam { } } + Context 'Get-VSTeamGitRef with Filter' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*filter=refs*" + } + + Get-VSTeamGitRef -ProjectName Test -RepositoryId 00000000-0000-0000-0000-000000000000 -Filter "refs/heads" + + It 'Should return a single ref with filter' { + Assert-VerifiableMock + } + } + + Context 'Get-VSTeamGitRef with FilterContains' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*filterContains=test" + } + + Get-VSTeamGitRef -ProjectName Test -RepositoryId 00000000-0000-0000-0000-000000000000 -FilterContains "test" + + It 'Should return a single ref' { + Assert-VerifiableMock + } + } + + Context 'Get-VSTeamGitRef with Top' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*`$top=100" + } + + Get-VSTeamGitRef -ProjectName Test -RepositoryId 00000000-0000-0000-0000-000000000000 -Top 100 + + It 'Should return a single ref' { + Assert-VerifiableMock + } + } + + Context 'Get-VSTeamGitRef with ContinuationToken' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*continuationToken=myToken" + } + + Get-VSTeamGitRef -ProjectName Test -RepositoryId 00000000-0000-0000-0000-000000000000 -ContinuationToken "myToken" + + It 'Should return a single ref' { + Assert-VerifiableMock + } + } + + Context 'Get-VSTeamGitRef with Filter, FilterContains, Top' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*filter=/refs/heads*" -and + $Uri -like "*`$top=500*" -and + $Uri -like "*filterContains=test*" + } + + Get-VSTeamGitRef -ProjectName Test -RepositoryId 00000000-0000-0000-0000-000000000000 -Filter "/refs/heads" -FilterContains "test" -Top 500 + + It 'Should return a single ref' { + Assert-VerifiableMock + } + } + Context 'Get-VSTeamGitRef by id throws' { Mock Invoke-RestMethod { throw [System.Net.WebException] "Test Exception." } From ac4948ddb2e6ce0e133c587d63467a4e84d88c73 Mon Sep 17 00:00:00 2001 From: Michel Zehnder Date: Wed, 19 Feb 2020 15:11:56 +0100 Subject: [PATCH 2/3] Update Documentation --- .docs/Get-VSTeamGitRef.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.docs/Get-VSTeamGitRef.md b/.docs/Get-VSTeamGitRef.md index 8b2669bd2..7f0d246d7 100644 --- a/.docs/Get-VSTeamGitRef.md +++ b/.docs/Get-VSTeamGitRef.md @@ -36,6 +36,38 @@ Aliases: ID Accept pipeline input: true (ByPropertyName) ``` +### -Filter + +A filter to apply to the refs (starts with). + +```yaml +Type: string +``` + +### -FilterContains + +A filter to apply to the refs (contains). (Azure DevOps Service and Azure DevOps Server 2019+ only) + +```yaml +Type: string +``` + +### -Top + +Maximum number of refs to return. It cannot be bigger than 1000. If it is not provided but continuationToken is, top will default to 100. (Azure DevOps Service and Azure DevOps Server 2019+ only) + +```yaml +Type: int +``` + +### -ContinuationToken + +The continuation token used for pagination. (Azure DevOps Service and Azure DevOps Server 2019+ only) + +```yaml +Type: string +``` + ## INPUTS ## OUTPUTS From 603ab7833fb7d59fc46144fab1393e2ac127a579 Mon Sep 17 00:00:00 2001 From: Michel Zehnder Date: Wed, 19 Feb 2020 15:14:31 +0100 Subject: [PATCH 3/3] Update Changelog with PR information --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0db93afa..fc96d3fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 6.4.5 +Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/237) from [Michel Zehnder](https://github.com/MichelZ) which included the following: + - Add -Filter, -FilterContains, -Top and -ContinuationToken to Get-VSTeamGitRefs ## 6.4.4