Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Filter, -FilterContains, -Top and -ContinuationToken to Get-VSTeamGitRefs #237

Merged
merged 3 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .docs/Get-VSTeamGitRef.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 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

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/231) from [Dave Neeley](https://github.com/daveneeley) which included the following:
Expand Down
21 changes: 19 additions & 2 deletions Source/Public/Get-VSTeamGitRef.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = @()

Expand Down
4 changes: 2 additions & 2 deletions Source/VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'VSTeam.psm1'

# Version number of this module.
ModuleVersion = '6.4.4'
ModuleVersion = '6.4.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -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.'
Expand Down
62 changes: 62 additions & 0 deletions unit/test/refs.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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." }

Expand Down