Skip to content

Commit

Permalink
Merge pull request #38 from jeffrey-opdam/feature/Approval_AssignedTo…
Browse files Browse the repository at this point in the history
…_Group

Added support for assigner to be a group, when requesting approvals f…
  • Loading branch information
DarqueWarrior authored Mar 15, 2018
2 parents 9dddd52 + 5a58c42 commit a875df9
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
33 changes: 22 additions & 11 deletions .docs/Get-VSTeamApproval.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,55 @@
# Get-VSTeamApproval

## SYNOPSIS

#include "./synopsis/Get-VSTeamApproval.md"

## SYNTAX

```
```powershell
Get-VSTeamApproval [-ProjectName] <String> [[-StatusFilter] <String>] [[-ReleaseIdsFilter] <Int32[]>]
[[-AssignedToFilter] <String>]
```

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

Expand All @@ -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
Expand All @@ -72,6 +80,7 @@ Accept wildcard characters: False
```
### -ReleaseIdsFilter
Only approvals for the release ids provided will be returned.
```yaml
Expand All @@ -87,6 +96,7 @@ Accept wildcard characters: False
```
### -AssignedToFilter
Approvals are filtered to only those assigned to this user.
```yaml
Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
RootModule = ''

# Version number of this module.
ModuleVersion = '2.1.7'
ModuleVersion = '2.1.8'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
16 changes: 9 additions & 7 deletions en-US/VSTeam-Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3131,19 +3131,21 @@ PS C:\&gt; Add-VSTeamRelease -DefinitionId 1 -Description Test -ArtifactAlias De
<maml:description>
<maml:para>The Get-VSTeamApproval function gets the approvals for all releases for a team project.</maml:para>
<maml:para>With just a project name, this function gets all of the pending approvals for that team project.</maml:para>
<maml:para>When using with VSTS "IncludeMyGroupApprovals" will be added to the request when Assigned To Filter is not empty.</maml:para>
<maml:para>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.</maml:para>
<maml:para>The Team.Approval type has three custom table formats:</maml:para>
<maml:para>Pending: ID, Status, Release Name, Environment, Type, Approver Name, Release Definitions</maml:para>
<maml:para>Approved: Release Name, Environment, Is Automated, Approval Type, Approver Name, Release Definitions, Comments</maml:para>
<maml:para>Rejected: Release Name, Environment, Approval Type, Approver Name, Release Definition, Comments</maml:para>
<maml:para>- Pending: ID, Status, Release Name, Environment, Type, Approver Name, Release Definitions</maml:para>
<maml:para>- Approved: Release Name, Environment, Is Automated, Approval Type, Approver Name, Release Definitions, Comments</maml:para>
<maml:para>- Rejected: Release Name, Environment, Approval Type, Approver Name, Release Definition, Comments</maml:para>
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>Get-VSTeamApproval</maml:name>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
<maml:name>StatusFilter</maml:name>
<maml:Description>
<maml:para>By default the function returns Pending approvals. </maml:para>
<maml:para>Using this filter you can return Approved, ReAssigned or Rejected approvals. </maml:para>
<maml:para>By default the function returns Pending approvals.</maml:para>
<maml:para>Using this filter you can return Approved, ReAssigned or Rejected approvals.</maml:para>
<maml:para>There is a custom table view for each status.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
Expand Down Expand Up @@ -3197,8 +3199,8 @@ PS C:\&gt; Add-VSTeamRelease -DefinitionId 1 -Description Test -ArtifactAlias De
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="0" aliases="none">
<maml:name>StatusFilter</maml:name>
<maml:Description>
<maml:para>By default the function returns Pending approvals. </maml:para>
<maml:para>Using this filter you can return Approved, ReAssigned or Rejected approvals. </maml:para>
<maml:para>By default the function returns Pending approvals.</maml:para>
<maml:para>Using this filter you can return Approved, ReAssigned or Rejected approvals.</maml:para>
<maml:para>There is a custom table view for each status.</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
Expand Down
24 changes: 21 additions & 3 deletions src/Approvals.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/team.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ function Invoke-VSTeamRequest {
$output = _callAPI @params

if ($JSON.IsPresent) {
$output | ConvertTo-Json
$output | ConvertTo-Json -Depth 99
}
else {
$output
Expand Down
26 changes: 26 additions & 0 deletions unit/test/Approvals.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit a875df9

Please sign in to comment.