diff --git a/.docs/Get-VSTeamApproval.md b/.docs/Get-VSTeamApproval.md index 63ca4d1f5..2d909d7ab 100644 --- a/.docs/Get-VSTeamApproval.md +++ b/.docs/Get-VSTeamApproval.md @@ -3,48 +3,55 @@ # Get-VSTeamApproval ## SYNOPSIS + #include "./synopsis/Get-VSTeamApproval.md" ## SYNTAX -``` +```powershell Get-VSTeamApproval [-ProjectName] [[-StatusFilter] ] [[-ReleaseIdsFilter] ] [[-AssignedToFilter] ] ``` ## DESCRIPTION + The Get-VSTeamApproval function gets the approvals for all releases for a team project. With just a project name, this function gets all of the pending approvals for that team project. -The Team.Approval type has three custom table formats: +When using with VSTS "IncludeMyGroupApprovals" will be added to the request when Assigned To Filter is not empty. -Pending: ID, Status, Release Name, Environment, Type, Approver Name, Release Definitions +When using with TFS "IncludeMyGroupApprovals" will be added to the request when Assigned To Filter, Release Id Filter are not empty and Status Filter equals Pending. -Approved: Release Name, Environment, Is Automated, Approval Type, Approver Name, Release Definitions, Comments +The Team.Approval type has three custom table formats: -Rejected: Release Name, Environment, Approval Type, Approver Name, Release Definition, Comments +- Pending: ID, Status, Release Name, Environment, Type, Approver Name, Release Definitions +- Approved: Release Name, Environment, Is Automated, Approval Type, Approver Name, Release Definitions, Comments +- Rejected: Release Name, Environment, Approval Type, Approver Name, Release Definition, Comments ## EXAMPLES ### -------------------------- EXAMPLE 1 -------------------------- -``` + +```powershell PS C:\> Get-VSTeamApproval -ProjectName Demo ``` This command gets a list of all pending approvals. ### -------------------------- EXAMPLE 2 -------------------------- -``` + +```powershell PS C:\> Get-VSTeamApproval -ProjectName Demo -StatusFilter Approved | Format-Table -View Approved ``` This command gets a list of all approved approvals using a custom table format. ### -------------------------- EXAMPLE 3 -------------------------- -``` + +```powershell PS C:\> Get-VSTeamApproval -ProjectName Demo -AssignedToFilter Administrator -StatusFilter Rejected | FT -View Rejected ``` @@ -53,16 +60,17 @@ This command gets a list of all approvals rejected by Administrator using a cust ## PARAMETERS ### -StatusFilter -By default the function returns Pending approvals. -Using this filter you can return Approved, ReAssigned or Rejected approvals. +By default the function returns Pending approvals. + +Using this filter you can return Approved, ReAssigned or Rejected approvals. There is a custom table view for each status. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: 0 @@ -72,6 +80,7 @@ Accept wildcard characters: False ``` ### -ReleaseIdsFilter + Only approvals for the release ids provided will be returned. ```yaml @@ -87,6 +96,7 @@ Accept wildcard characters: False ``` ### -AssignedToFilter + Approvals are filtered to only those assigned to this user. ```yaml @@ -112,6 +122,7 @@ Accept wildcard characters: False ### Team.BuildDefinition ## NOTES + This function has a Dynamic Parameter for ProjectName that specifies the project for which this function gets build definitions. diff --git a/README.md b/README.md index 3b786e022..470ba23ef 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,12 @@ The cases of every file is very important. This module is to be used on Windows, ## Release Notes +### 2.1.8 + +Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/38) from [Jeffrey Opdam](https://github.com/jeffrey-opdam) which included the following: + +- Added support for assigner to be a group, when requesting approvals for a group + ### 2.1.7 Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/42) from [Michal Karpinski](https://github.com/karpis) which included the following: diff --git a/VSTeam.psd1 b/VSTeam.psd1 index 581e6331d..3ae18a8d8 100644 --- a/VSTeam.psd1 +++ b/VSTeam.psd1 @@ -13,7 +13,7 @@ RootModule = '' # Version number of this module. - ModuleVersion = '2.1.7' + ModuleVersion = '2.1.8' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/en-US/VSTeam-Help.xml b/en-US/VSTeam-Help.xml index 5d224ddee..eb6cfd24b 100644 --- a/en-US/VSTeam-Help.xml +++ b/en-US/VSTeam-Help.xml @@ -3131,10 +3131,12 @@ PS C:\> Add-VSTeamRelease -DefinitionId 1 -Description Test -ArtifactAlias De The Get-VSTeamApproval function gets the approvals for all releases for a team project. With just a project name, this function gets all of the pending approvals for that team project. + When using with VSTS "IncludeMyGroupApprovals" will be added to the request when Assigned To Filter is not empty. + When using with TFS "IncludeMyGroupApprovals" will be added to the request when Assigned To Filter, Release Id Filter are not empty and Status Filter equals Pending. The Team.Approval type has three custom table formats: - Pending: ID, Status, Release Name, Environment, Type, Approver Name, Release Definitions - Approved: Release Name, Environment, Is Automated, Approval Type, Approver Name, Release Definitions, Comments - Rejected: Release Name, Environment, Approval Type, Approver Name, Release Definition, Comments + - Pending: ID, Status, Release Name, Environment, Type, Approver Name, Release Definitions + - Approved: Release Name, Environment, Is Automated, Approval Type, Approver Name, Release Definitions, Comments + - Rejected: Release Name, Environment, Approval Type, Approver Name, Release Definition, Comments @@ -3142,8 +3144,8 @@ PS C:\> Add-VSTeamRelease -DefinitionId 1 -Description Test -ArtifactAlias De StatusFilter - By default the function returns Pending approvals. - Using this filter you can return Approved, ReAssigned or Rejected approvals. + By default the function returns Pending approvals. + Using this filter you can return Approved, ReAssigned or Rejected approvals. There is a custom table view for each status. String @@ -3197,8 +3199,8 @@ PS C:\> Add-VSTeamRelease -DefinitionId 1 -Description Test -ArtifactAlias De StatusFilter - By default the function returns Pending approvals. - Using this filter you can return Approved, ReAssigned or Rejected approvals. + By default the function returns Pending approvals. + Using this filter you can return Approved, ReAssigned or Rejected approvals. There is a custom table view for each status. String diff --git a/src/Approvals.psm1 b/src/Approvals.psm1 index 2b3742b3a..33d655030 100644 --- a/src/Approvals.psm1 +++ b/src/Approvals.psm1 @@ -34,9 +34,27 @@ function Get-VSTeamApproval { $ProjectName = $PSBoundParameters["ProjectName"] try { + # Build query string and determine if the includeMyGroupApprovals should be added. + $queryString = @{statusFilter = $StatusFilter; assignedtoFilter = $AssignedToFilter; releaseIdsFilter = ($ReleaseIdsFilter -join ',')} + + # The support in TFS and VSTS are not the same. + if (_isVSTS $VSTeamVersionTable.Account) { + if ($AssignedToFilter -ne $null -and $AssignedToFilter -ne "") { + $queryString.includeMyGroupApprovals = 'true'; + } + } + else { + # For TFS all three parameters must be set before you can add + # includeMyGroupApprovals. + if ($AssignedToFilter -ne $null -and $AssignedToFilter -ne "" -and + $ReleaseIdsFilter -ne $null -and $ReleaseIdsFilter -ne "" -and + $StatusFilter -eq 'Pending') { + $queryString.includeMyGroupApprovals = 'true'; + } + } + # Call the REST API - $resp = _callAPI -ProjectName $ProjectName -Area release -Resource approvals -SubDomain vsrm -Version $VSTeamVersionTable.Release ` - -QueryString @{statusFilter = $StatusFilter; assignedtoFilter = $AssignedToFilter; releaseIdsFilter = ($ReleaseIdsFilter -join ',')} + $resp = _callAPI -ProjectName $ProjectName -Area release -Resource approvals -SubDomain vsrm -Version $VSTeamVersionTable.Release -QueryString $queryString # Apply a Type Name so we can use custom format view and custom type extensions foreach ($item in $resp.value) { @@ -129,4 +147,4 @@ Set-Alias Set-Approval Set-VSTeamApproval Export-ModuleMember ` -Function Get-VSTeamApproval, Set-VSTeamApproval, Show-VSTeamApproval ` - -Alias Show-Approval, Get-Approval, Set-Approval + -Alias Show-Approval, Get-Approval, Set-Approval \ No newline at end of file diff --git a/src/team.psm1 b/src/team.psm1 index 81dd5004b..5ebf3a01a 100644 --- a/src/team.psm1 +++ b/src/team.psm1 @@ -434,7 +434,7 @@ function Invoke-VSTeamRequest { $output = _callAPI @params if ($JSON.IsPresent) { - $output | ConvertTo-Json + $output | ConvertTo-Json -Depth 99 } else { $output diff --git a/unit/test/Approvals.Tests.ps1 b/unit/test/Approvals.Tests.ps1 index 405f0e317..0651e5291 100644 --- a/unit/test/Approvals.Tests.ps1 +++ b/unit/test/Approvals.Tests.ps1 @@ -63,6 +63,32 @@ InModuleScope Approvals { } } + Context 'Get-VSTeamApproval with AssignedToFilter' { + Mock Invoke-RestMethod { + return @{ + count = 1 + value = @( + @{ + id = 1 + revision = 1 + approver = @{ + id = 'c1f4b9a6-aee1-41f9-a2e0-070a79973ae9' + displayName = 'Test User' + } + } + ) + }} + + Get-VSTeamApproval -projectName project -AssignedToFilter 'Chuck Reinhart' + + It 'should return approvals' { + Assert-MockCalled Invoke-RestMethod -Exactly -Scope Context -Times 1 ` + -ParameterFilter { + $Uri -eq "https://test.vsrm.visualstudio.com/project/_apis/release/approvals/?api-version=$($VSTeamVersionTable.Release)&assignedtoFilter=Chuck%20Reinhart&includeMyGroupApprovals=true" + } + } + } + # This makes sure the alias is working Context 'Get-Approval' { Mock _useWindowsAuthenticationOnPremise { return $true }