From ad41d9412205c60e74960707c0b96a132f6e72e5 Mon Sep 17 00:00:00 2001 From: Michel Zehnder Date: Thu, 20 Feb 2020 13:43:37 +0100 Subject: [PATCH 1/2] Add Get-VSTeamGitCommit --- .docs/Get-VSTeamGitCommit.md | 237 ++++++++++++++++++ .docs/synopsis/Get-VSTeamGitCommit.md | 1 + CHANGELOG.md | 6 + Source/Classes/VSTeamGitCommitRef.ps1 | 25 ++ Source/Classes/VSTeamGitUserDate.ps1 | 18 ++ Source/Classes/_classes.json | 4 +- Source/Public/Get-VSTeamGitCommit.ps1 | 151 +++++++++++ .../Team.GitCommitRef.TableView.ps1xml | 48 ++++ .../formats/Team.GitUserDate.TableView.ps1xml | 35 +++ Source/formats/_formats.json | 4 +- unit/test/Get-VSTeamGitCommit.Tests.ps1 | 140 +++++++++++ 11 files changed, 667 insertions(+), 2 deletions(-) create mode 100644 .docs/Get-VSTeamGitCommit.md create mode 100644 .docs/synopsis/Get-VSTeamGitCommit.md create mode 100644 Source/Classes/VSTeamGitCommitRef.ps1 create mode 100644 Source/Classes/VSTeamGitUserDate.ps1 create mode 100644 Source/Public/Get-VSTeamGitCommit.ps1 create mode 100644 Source/formats/Team.GitCommitRef.TableView.ps1xml create mode 100644 Source/formats/Team.GitUserDate.TableView.ps1xml create mode 100644 unit/test/Get-VSTeamGitCommit.Tests.ps1 diff --git a/.docs/Get-VSTeamGitCommit.md b/.docs/Get-VSTeamGitCommit.md new file mode 100644 index 000000000..4b50b1582 --- /dev/null +++ b/.docs/Get-VSTeamGitCommit.md @@ -0,0 +1,237 @@ + + +# Get-VSTeamBuild + +## SYNOPSIS + + + +## SYNTAX + +## DESCRIPTION + +The Get-VSTeamGitCommit function gets the commits for a git repository. + +## EXAMPLES + +### -------------------------- EXAMPLE 1 -------------------------- + +```PowerShell +PS C:\> Get-VSTeamGitCommit -ProjectName demo -RepositoryId 118C262F-0D4C-4B76-BD9B-7DD8CA12F196 +``` + +This command gets a list of all commits in the demo project for a specific repository. + +## PARAMETERS + + + +### -RepositoryId + +The id or friendly name of the repository. To use the friendly name, projectId must also be specified. + +```yaml +Type: Guid +Required: True +Accept pipeline input: true (ByPropertyName) +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath, ByIds +``` + +### -FromDate + +If provided, only include history entries created after this date (string) + +```yaml +Type: DateTime +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -ToDate + +If provided, only include history entries created before this date (string) + +```yaml +Type: DateTime +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -ItemVersionVersionType + +Version type (branch, tag, or commit). Determines how Id is interpreted. The acceptable values for this parameter are: + +- branch +- commit +- tag + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -ItemVersionVersion + +Version string identifier (name of tag/branch, SHA1 of commit) + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -ItemVersionVersionOptions + +Version options - Specify additional modifiers to version (e.g Previous). The acceptable values for this parameter are: + +- firstParent +- none +- previousChange + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -CompareVersionVersionType + +Version type (branch, tag, or commit). Determines how Id is interpreted. The acceptable values for this parameter are: + +- branch +- commit +- tag + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -CompareVersionVersion + +Version string identifier (name of tag/branch, SHA1 of commit). The acceptable values for this parameter are: + +- firstParent +- none +- previousChange + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -CompareVersionVersionOptions + +Version options - Specify additional modifiers to version (e.g Previous) + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -FromCommitId + +If provided, a lower bound for filtering commits alphabetically + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -ToCommitId + +If provided, an upper bound for filtering commits alphabetically + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -Author + +Alias or display name of the author + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -Ids + +If provided, specifies the exact commit ids of the commits to fetch. May not be combined with other parameters. + +```yaml +Type: String +Parameter Sets: ByIds +``` + +### -ItemPath + +Path of item to search under + +```yaml +Type: String +Parameter Sets: All, ItemPath +``` + +### -ExcludeDeletes + +Only applies when an itemPath is specified. This determines whether to exclude delete entries of the specified path. + +```yaml +Type: Switch +Parameter Sets: All, ItemPath +``` + +### -Top + +Maximum number of entries to retrieve + +```yaml +Type: Int32 +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -Skip + +Number of entries to skip + +```yaml +Type: Int32 +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +### -HistoryMode + +What Git history mode should be used. This only applies to the search criteria when Ids = null and an itemPath is specified. The acceptable values for this parameter are: + +- firstParent +- fullHistory +- fullHistorySimplifyMerges +- simplifiedHistory + +```yaml +Type: String +Parameter Sets: ItemPath +``` + +### -User + +Alias or display name of the committer + +```yaml +Type: String +Parameter Sets: All, ItemVersion, CompareVersion, ItemPath +``` + +## INPUTS + +## OUTPUTS + +## NOTES + +This function has a Dynamic Parameter for ProjectName that specifies the project for which this function gets commits. + +You can tab complete from a list of available projects. + +You can use Set-VSTeamDefaultProject to set a default project so you do not have to pass the ProjectName with each call. + +You can pipe a repository ID to this function. + +## RELATED LINKS diff --git a/.docs/synopsis/Get-VSTeamGitCommit.md b/.docs/synopsis/Get-VSTeamGitCommit.md new file mode 100644 index 000000000..a137188a7 --- /dev/null +++ b/.docs/synopsis/Get-VSTeamGitCommit.md @@ -0,0 +1 @@ +Retrieve git commits for a project \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e88b6495..3eaf02f23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 6.4.6 + +Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/238) from [Michel Zehnder](https://github.com/MichelZ) which included the following: + +- Added Get-VSTeamGitCommit to retrieve commits + ## 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/Classes/VSTeamGitCommitRef.ps1 b/Source/Classes/VSTeamGitCommitRef.ps1 new file mode 100644 index 000000000..01b1f5cae --- /dev/null +++ b/Source/Classes/VSTeamGitCommitRef.ps1 @@ -0,0 +1,25 @@ +class VSTeamGitCommitRef : VSTeamLeaf { + [VSTeamGitUserDate]$Author = $null + [VSTeamGitUserDate]$Committer = $null + [string]$Comment=$null + [string]$CommitId = $null + [string]$RemoteUrl = $null + [string]$Url = $null + + VSTeamGitCommitRef ( + [object]$obj, + [string]$ProjectName + ) : base($obj.comment, $obj.commitId, $ProjectName) { + + $this.Author = [VSTeamGitUserDate]::new($obj.author, $ProjectName) + $this.Committer = [VSTeamGitUserDate]::new($obj.committer, $ProjectName) + $this.CommitId = $obj.commitId + $this.Comment = $obj.comment + $this.RemoteUrl = $obj.remoteUrl + $this.Url = $obj.url + + $this._internalObj = $obj + + $this.AddTypeName('Team.GitCommitRef') + } +} \ No newline at end of file diff --git a/Source/Classes/VSTeamGitUserDate.ps1 b/Source/Classes/VSTeamGitUserDate.ps1 new file mode 100644 index 000000000..702f949e0 --- /dev/null +++ b/Source/Classes/VSTeamGitUserDate.ps1 @@ -0,0 +1,18 @@ +class VSTeamGitUserDate : VSTeamLeaf { + [DateTime]$Date = [DateTime]::MinValue + [string]$Email = $null + + VSTeamGitUserDate ( + [object]$obj, + [string]$ProjectName + ) : base($obj.email, $obj.email, $ProjectName) { + + $this.Date = $obj.date + $this.Email = $obj.email + $this.Name = $obj.name + + $this._internalObj = $obj + + $this.AddTypeName('Team.GitUserDate') + } +} \ No newline at end of file diff --git a/Source/Classes/_classes.json b/Source/Classes/_classes.json index bfe9bf964..00421be5e 100644 --- a/Source/Classes/_classes.json +++ b/Source/Classes/_classes.json @@ -56,6 +56,8 @@ "VSTeamJobRequest.ps1", "VSTeamReleaseDefinition.ps1", "VSTeamReleaseDefinitions.ps1", - "VSTeamPermissionInheritance.ps1" + "VSTeamPermissionInheritance.ps1", + "VSTeamGitCommitRef.ps1", + "VSTeamGitUserDate.ps1" ] } \ No newline at end of file diff --git a/Source/Public/Get-VSTeamGitCommit.ps1 b/Source/Public/Get-VSTeamGitCommit.ps1 new file mode 100644 index 000000000..da2ade62c --- /dev/null +++ b/Source/Public/Get-VSTeamGitCommit.ps1 @@ -0,0 +1,151 @@ +function Get-VSTeamGitCommit { + [CmdletBinding(DefaultParameterSetName='All')] + param ( + [Parameter(ParameterSetName = 'All', ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)] + [Parameter(ParameterSetName = 'ItemVersion', ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)] + [Parameter(ParameterSetName = 'CompareVersion', ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)] + [Parameter(ParameterSetName = 'ByIds', ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)] + [Parameter(ParameterSetName = 'ItemPath', ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)] + [Alias('Id')] + [Guid] $RepositoryID, + [Parameter(ParameterSetName = 'All', HelpMessage="FromDate, in UTC")] + [Parameter(ParameterSetName = 'ItemVersion', HelpMessage="FromDate, in UTC")] + [Parameter(ParameterSetName = 'CompareVersion', HelpMessage="FromDate, in UTC")] + [Parameter(ParameterSetName = 'ItemPath', HelpMessage="FromDate, in UTC")] + [DateTime] $FromDate, + [Parameter(ParameterSetName = 'All', HelpMessage="ToDate, in UTC")] + [Parameter(ParameterSetName = 'ItemVersion', HelpMessage="ToDate, in UTC")] + [Parameter(ParameterSetName = 'CompareVersion', HelpMessage="ToDate, in UTC")] + [Parameter(ParameterSetName = 'ItemPath', HelpMessage="ToDate, in UTC")] + [DateTime] $ToDate, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion', Mandatory = $true)] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [ValidateSet('branch', 'commit', 'tag')] + [string] $ItemVersionVersionType, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion', Mandatory = $true)] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [string] $ItemVersionVersion, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion', Mandatory = $false)] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [ValidateSet('firstParent', 'none', 'previousChange')] + [string] $ItemVersionVersionOptions, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'CompareVersion', Mandatory = $true)] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [ValidateSet('branch', 'commit', 'tag')] + [string] $CompareVersionVersionType, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'CompareVersion', Mandatory = $true)] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [string] $CompareVersionVersion, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'CompareVersion', Mandatory = $false)] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [ValidateSet('firstParent', 'none', 'previousChange')] + [string] $CompareVersionVersionOptions, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [string] $FromCommitId, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [string] $ToCommitId, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [string] $Author, + [Parameter(ParameterSetName = "ByIds")] + [string[]] $Ids, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemPath', Mandatory = $true)] + [string] $ItemPath, + [Parameter(ParameterSetName = 'ItemPath')] + [switch] $ExcludeDeletes, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [int] $Top, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [int] $Skip, + [Parameter(ParameterSetName = 'ItemPath')] + [ValidateSet('firstParent','fullHistory','fullHistorySimplifyMerges','simplifiedHistory')] + [string] $HistoryMode, + [Parameter(ParameterSetName = 'All')] + [Parameter(ParameterSetName = 'ItemVersion')] + [Parameter(ParameterSetName = 'CompareVersion')] + [Parameter(ParameterSetName = 'ItemPath')] + [string] $User + ) + + DynamicParam { + _buildProjectNameDynamicParam + } + + process { + # Bind the parameter to a friendly variable + $ProjectName = $PSBoundParameters["ProjectName"] + + if (($ItemVersionVersionType -eq "commit") -and ($ItemVersionVersion -eq $null -or $ItemVersionVersion -eq '')) + { + throw "If you have a -ItemVersionVersionType of 'commit' you need to set a commit id as -ItemVersionVersion"; + } + + if (($CompareVersionVersionType -eq "commit") -and ($CompareVersionVersion -eq $null -or $CompareVersionVersion -eq '')) + { + throw "If you have a -CompareVersionVersionType of 'commit' you need to set a commit id as -CompareVersionVersion"; + } + + try { + $queryString = @{ + 'searchCriteria.fromDate' = if ($FromDate) { $FromDate.ToString('yyyy-MM-ddTHH:mm:ssZ') } else { $null } + 'searchCriteria.toDate' = if ($ToDate) { $ToDate.ToString('yyyy-MM-ddTHH:mm:ssZ') } else { $null } + 'searchCriteria.itemVersion.versionType' = $ItemVersionVersionType + 'searchCriteria.itemVersion.version' = $ItemVersionVersion + 'searchCriteria.itemVersion.versionOptions' = $ItemVersionVersionOptions + 'searchCriteria.compareVersion.versionType' = $CompareVersionVersionType + 'searchCriteria.compareVersion.version' = $CompareVersionVersion + 'searchCriteria.compareVersion.versionOptions' = $CompareVersionVersionOptions + 'searchCriteria.fromCommitId' = $FromCommitId + 'searchCriteria.toCommitId' = $ToCommitId + 'searchCriteria.author' = $Author + 'searchCriteria.ids' = $Ids + 'searchCriteria.itemPath' = $ItemPath + 'searchCriteria.excludeDeletes' = $ExcludeDeletes + 'searchCriteria.historyMode' = $HistoryMode + 'searchCriteria.$top' = $Top + 'searchCriteria.$skip' = $Skip + 'searchCriteria.user' = $User + } + + $resp = _callAPI -ProjectName $ProjectName -Id "$RepositoryID/commits" -Area git -Resource repositories -Version $([VSTeamVersions]::Git) -QueryString $queryString + + $obj = @() + + foreach ($item in $resp.value) { + $obj += [VSTeamGitCommitRef]::new($item, $ProjectName) + } + + Write-Output $obj + } + catch { + throw $_ + } + } +} \ No newline at end of file diff --git a/Source/formats/Team.GitCommitRef.TableView.ps1xml b/Source/formats/Team.GitCommitRef.TableView.ps1xml new file mode 100644 index 000000000..3952361db --- /dev/null +++ b/Source/formats/Team.GitCommitRef.TableView.ps1xml @@ -0,0 +1,48 @@ + + + + + Team.GitCommitRef.TableView + + Team.GitCommitRef + Team.GitUserDate + + + + + + + + + + + + + + + + + + + + + + + CommitId + + + $_.Committer.Date + + + $_.Committer.Name + + + Comment + + + + + + + + diff --git a/Source/formats/Team.GitUserDate.TableView.ps1xml b/Source/formats/Team.GitUserDate.TableView.ps1xml new file mode 100644 index 000000000..92ee7962b --- /dev/null +++ b/Source/formats/Team.GitUserDate.TableView.ps1xml @@ -0,0 +1,35 @@ + + + + + Team.GitUserDate.TableView + + Team.GitUserDate + + + + + + + + + + + + + + + + + Name + + + EMail + + + + + + + + diff --git a/Source/formats/_formats.json b/Source/formats/_formats.json index f4f6ff1eb..0a26e9a2d 100644 --- a/Source/formats/_formats.json +++ b/Source/formats/_formats.json @@ -95,6 +95,8 @@ "Team.WorkItem.ListView.ps1xml", "Team.WorkItemDeleted.TableView.ps1xml", "Team.WorkItemDeleted.ListView.ps1xml", - "Team.JobRequest.TableView.ps1xml" + "Team.JobRequest.TableView.ps1xml", + "Team.GitCommitRef.TableView.ps1xml", + "Team.GitUserDate.TableView.ps1xml" ] } \ No newline at end of file diff --git a/unit/test/Get-VSTeamGitCommit.Tests.ps1 b/unit/test/Get-VSTeamGitCommit.Tests.ps1 new file mode 100644 index 000000000..ec98a139f --- /dev/null +++ b/unit/test/Get-VSTeamGitCommit.Tests.ps1 @@ -0,0 +1,140 @@ +Set-StrictMode -Version Latest + +InModuleScope VSTeam { + + # Set the account to use for testing. A normal user would do this + # using the Set-VSTeamAccount function. + [VSTeamVersions]::Account = 'https://dev.azure.com/test' + + $results = [PSCustomObject]@{ + count = 2 + value = @( + [PSCustomObject]@{ + author = [PSCustomObject]@{ + date = '2020-02-19T15:12:01Z' + email = 'test@test.com' + name = 'Test User' + } + changeCounts = [PSCustomObject]@{ + Add = 2 + Delete = 0 + Edit = 1 + } + comment = 'Just a test commit' + commitId = '1234567890abcdef1234567890abcdef' + committer = [PSCustomObject]@{ + date = '2020-02-19T15:12:01Z' + email = 'test@test.com' + name = 'Test User' + } + remoteUrl = 'https://dev.azure.com/test/test/_git/test/commit/1234567890abcdef1234567890abcdef' + url = 'https://dev.azure.com/test/21AF684D-AFFB-4F9A-9D49-866EF24D6A4A/_apid/git/repositories/06E176BE-D3D2-41C2-AB34-5F4D79AEC86B/commits/1234567890abcdef1234567890abcdef' + }, + [PSCustomObject]@{ + author = [PSCustomObject]@{ + date = '2020-02-20T01:00:01Z' + email = 'eample@example.com' + name = 'Example User' + } + changeCounts = [PSCustomObject]@{ + Add = 8 + Delete = 1 + Edit = 0 + } + comment = 'Just another test commit' + commitId = 'abcdef1234567890abcdef1234567890' + committer = [PSCustomObject]@{ + date = '2020-02-20T01:00:01Z' + email = 'eample@example.com' + name = 'Example User' + } + remoteUrl = 'https://dev.azure.com/test/test/_git/test/commit/abcdef1234567890abcdef1234567890' + url = 'https://dev.azure.com/test/21AF684D-AFFB-4F9A-9D49-866EF24D6A4A/_apid/git/repositories/06E176BE-D3D2-41C2-AB34-5F4D79AEC86B/commits/abcdef1234567890abcdef1234567890' + } + ) + } + + Describe "Git VSTS" { + # Mock the call to Get-Projects by the dynamic parameter for ProjectName + Mock Invoke-RestMethod { return @() } -ParameterFilter { + $Uri -like "*_apis/projects*" + } + + . "$PSScriptRoot\mocks\mockProjectNameDynamicParam.ps1" + + Context 'Get-VSTeamGitCommit' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*repositories/06E176BE-D3D2-41C2-AB34-5F4D79AEC86B/commits*" + } + + Get-VSTeamGitCommit -ProjectName Test -RepositoryId 06E176BE-D3D2-41C2-AB34-5F4D79AEC86B + + It 'Should return all commits for the repo' { + Assert-VerifiableMock + } + } + + Context 'Get-VSTeamGitCommit with many Parameters' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*repositories/06E176BE-D3D2-41C2-AB34-5F4D79AEC86B/commits*" -and + $Uri -like "*searchCriteria.fromDate=2020-01-01T00:00:00Z*" -and + $Uri -like "*searchCriteria.toDate=2020-03-01T00:00:00Z*" -and + $Uri -like "*searchCriteria.itemVersion.versionType=commit*" -and + $Uri -like "*searchCriteria.itemVersion.version=abcdef1234567890abcdef1234567890*" -and + $Uri -like "*searchCriteria.itemVersion.versionOptions=previousChange*" -and + $Uri -like "*searchCriteria.compareVersion.versionType=commit*" -and + $Uri -like "*searchCriteria.compareVersion.version=abcdef1234567890abcdef1234567890*" -and + $Uri -like "*searchCriteria.compareVersion.versionOptions=previousChange*" -and + $Uri -like "*searchCriteria.fromCommitId=abcdef*" -and + $Uri -like "*searchCriteria.toCommitId=fedcba*" -and + $Uri -like "*searchCriteria.author=Test*" -and + $Uri -like "*searchCriteria.user=Test*" -and + $Uri -like "*searchCriteria.`$top=100*" -and + $Uri -like "*searchCriteria.`$skip=50*" + } + + Get-VSTeamGitCommit -ProjectName Test -RepositoryId '06E176BE-D3D2-41C2-AB34-5F4D79AEC86B' ` + -FromDate '2020-01-01' -ToDate '2020-03-01' ` + -ItemVersionVersionType 'commit' -ItemVersionVersion 'abcdef1234567890abcdef1234567890' -ItemVersionVersionOptions 'previousChange' ` + -CompareVersionVersionType 'commit' -CompareVersionVersion 'abcdef1234567890abcdef1234567890' -CompareVersionVersionOptions 'previousChange' ` + -FromCommitId 'abcdef' -ToCommitId 'fedcba' ` + -Author "Test" ` + -Top 100 -Skip 50 ` + -User "Test" + + It 'Should return all commits for the repo' { + Assert-VerifiableMock + } + } + + Context 'Get-VSTeamGitCommit with ItemPath parameters' { + Mock Invoke-RestMethod { return $results } -Verifiable -ParameterFilter { + $Uri -like "*repositories/06E176BE-D3D2-41C2-AB34-5F4D79AEC86B/commits*" -and + $Uri -like "*searchCriteria.itemPath=test*" -and + $Uri -like "*searchCriteria.excludeDeletes=true*" -and + $Uri -like "*searchCriteria.historyMode=fullHistory*" -and + $Uri -like "*searchCriteria.`$top=100*" -and + $Uri -like "*searchCriteria.`$skip=50*" + } + + Get-VSTeamGitCommit -ProjectName Test -RepositoryId '06E176BE-D3D2-41C2-AB34-5F4D79AEC86B' ` + -ItemPath 'test' ` + -ExcludeDeletes ` + -HistoryMode 'fullHistory' ` + -Top 100 -Skip 50 ` + -User "Test" + + It 'Should return all commits for the repo' { + Assert-VerifiableMock + } + } + + Context 'Get-VSTeamGitCommit by id throws' { + Mock Invoke-RestMethod { throw [System.Net.WebException] "Test Exception." } + + It 'Should throw' { + { Get-VSTeamGitCommit -ProjectName Test -RepositoryId 06E176BE-D3D2-41C2-AB34-5F4D79AEC86B } | Should Throw + } + } + } +} \ No newline at end of file From d04dcebb46419aad7c80b1cd0cbf583287cd886b Mon Sep 17 00:00:00 2001 From: Michel Zehnder Date: Thu, 20 Feb 2020 13:55:05 +0100 Subject: [PATCH 2/2] Fix Title --- .docs/Get-VSTeamGitCommit.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.docs/Get-VSTeamGitCommit.md b/.docs/Get-VSTeamGitCommit.md index 4b50b1582..1c050c155 100644 --- a/.docs/Get-VSTeamGitCommit.md +++ b/.docs/Get-VSTeamGitCommit.md @@ -1,6 +1,6 @@ -# Get-VSTeamBuild +# Get-VSTeamGitCommit ## SYNOPSIS