From 2855e3be5cd5b5d9637bdfa8a748f60a634ee47c Mon Sep 17 00:00:00 2001 From: Jeffrey Opdam Date: Thu, 1 Feb 2018 23:12:43 +0100 Subject: [PATCH 1/5] Added support for assigner to be a group, when requesting approvals for a group. --- README.md | 3 +++ src/Approvals.psm1 | 2 +- unit/test/Approvals.Tests.ps1 | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f486c7dd6..d89ba709e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ To get started you can visit this blog [PowerShell I would like you to meet TFS The cases of every file is very important. This module is to be used on Windows, Linux and OSx so case is important. If the casing does not match Linux and OSx might fail. # Release Notes +## 2.1.4 +Added support for assigner to be a group, when requesting approvals for a group. + ## 2.1.3 Added support for Service Endpoint Types diff --git a/src/Approvals.psm1 b/src/Approvals.psm1 index 37aa80c09..48ef85ad0 100644 --- a/src/Approvals.psm1 +++ b/src/Approvals.psm1 @@ -35,7 +35,7 @@ function Get-VSTeamApproval { try { # Call the REST API $resp = _callAPI -ProjectName $ProjectName -Area release -Resource approvals -SubDomain vsrm -Version $VSTeamVersionTable.Release ` - -QueryString @{statusFilter = $StatusFilter; assignedtoFilter = $AssignedToFilter; releaseIdFilter = ($ReleaseIdFilter -join ',')} + -QueryString @{includeMyGroupApprovals = 'true'; statusFilter = $StatusFilter; assignedtoFilter = $AssignedToFilter; releaseIdFilter = ($ReleaseIdFilter -join ',')} # Apply a Type Name so we can use custom format view and custom type extensions foreach ($item in $resp.value) { diff --git a/unit/test/Approvals.Tests.ps1 b/unit/test/Approvals.Tests.ps1 index 405f0e317..1fa43713f 100644 --- a/unit/test/Approvals.Tests.ps1 +++ b/unit/test/Approvals.Tests.ps1 @@ -58,7 +58,7 @@ InModuleScope Approvals { 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)" + $Uri -eq "https://test.vsrm.visualstudio.com/project/_apis/release/approvals/?api-version=$($VSTeamVersionTable.Release)&includeMyGroupApprovals=true" } } } @@ -85,7 +85,7 @@ InModuleScope Approvals { 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)" + $Uri -eq "https://test.vsrm.visualstudio.com/project/_apis/release/approvals/?api-version=$($VSTeamVersionTable.Release)&includeMyGroupApprovals=true" } } } From 2ba2bc103da72414be15ec07f4c5ab5a93206b43 Mon Sep 17 00:00:00 2001 From: Jeffrey Opdam Date: Wed, 7 Feb 2018 23:11:01 +0100 Subject: [PATCH 2/5] includemygroupapprovals is only used when the assignedtofilter is filled in. --- unit/test/Approvals.Tests.ps1 | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/unit/test/Approvals.Tests.ps1 b/unit/test/Approvals.Tests.ps1 index 1fa43713f..0651e5291 100644 --- a/unit/test/Approvals.Tests.ps1 +++ b/unit/test/Approvals.Tests.ps1 @@ -58,11 +58,37 @@ InModuleScope Approvals { 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)&includeMyGroupApprovals=true" + $Uri -eq "https://test.vsrm.visualstudio.com/project/_apis/release/approvals/?api-version=$($VSTeamVersionTable.Release)" } } } + 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 } @@ -85,7 +111,7 @@ InModuleScope Approvals { 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)&includeMyGroupApprovals=true" + $Uri -eq "https://test.vsrm.visualstudio.com/project/_apis/release/approvals/?api-version=$($VSTeamVersionTable.Release)" } } } From 5757a1766af45a41bc924fd08608a277c5e269c0 Mon Sep 17 00:00:00 2001 From: Jeffrey Opdam Date: Wed, 7 Feb 2018 23:41:28 +0100 Subject: [PATCH 3/5] Little tweak --- src/Approvals.psm1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Approvals.psm1 b/src/Approvals.psm1 index 4050a6c92..762f1a277 100644 --- a/src/Approvals.psm1 +++ b/src/Approvals.psm1 @@ -33,9 +33,14 @@ function Get-VSTeamApproval { $ProjectName = $PSBoundParameters["ProjectName"] try { + # Build query string and determine if the includeMyGroupApprovals should be added. + $queryString = @{statusFilter = $StatusFilter; assignedtoFilter = $AssignedToFilter; releaseIdFilter = ($ReleaseIdFilter -join ',')} + if($AssignedToFilter -ne $null -and $AssignedToFilter -ne ""){ + $queryString.includeMyGroupApprovals = 'true'; + } + # Call the REST API - $resp = _callAPI -ProjectName $ProjectName -Area release -Resource approvals -SubDomain vsrm -Version $VSTeamVersionTable.Release ` - -QueryString @{includeMyGroupApprovals = 'true'; statusFilter = $StatusFilter; assignedtoFilter = $AssignedToFilter; releaseIdFilter = ($ReleaseIdFilter -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) { From 7a6d46a2f7ffeed8ca10e60ee9ab1981e1a4479a Mon Sep 17 00:00:00 2001 From: DarqueWarrior Date: Thu, 15 Mar 2018 11:50:22 -0500 Subject: [PATCH 4/5] TFS and VSTS behave differently --- src/Approvals.psm1 | 24 +++++++++++++++++++++--- src/team.psm1 | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) 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 From c910d4d80bc9c786ed75b00ea21c021be0858410 Mon Sep 17 00:00:00 2001 From: DarqueWarrior Date: Thu, 15 Mar 2018 12:05:00 -0500 Subject: [PATCH 5/5] Updated the version, Readme and help. --- .docs/Get-VSTeamApproval.md | 33 ++++++++++++++++++++++----------- README.md | 6 ++++++ VSTeam.psd1 | 2 +- en-US/VSTeam-Help.xml | 16 +++++++++------- 4 files changed, 38 insertions(+), 19 deletions(-) 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