Skip to content

Commit

Permalink
Merge pull request #1 from fifthstreetpartners/feature/add-process-su…
Browse files Browse the repository at this point in the history
…pport

Adding Process Template Support
  • Loading branch information
fifthstreetpartners authored Jan 17, 2019
2 parents 20601b8 + de7194c commit 6fdfac0
Show file tree
Hide file tree
Showing 11 changed files with 535 additions and 37 deletions.
14 changes: 8 additions & 6 deletions .docs/Add-VSTeamProject.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ Position: 0
### -ProcessTemplate
The name of the process template to use for the project. The acceptable values for this parameter are:
The name of the process template to use for the project.
- Agile
- Scrum
- CMMI
You can tab complete from a list of available projects.
Will use the default process template if one is not provided
```yaml
Type: String
Default value: Scrum
Default value: [Determined by Default Process Template definition]
```
### -Description
Expand Down Expand Up @@ -84,4 +84,6 @@ Type: SwitchParameter
[Add-VSTeamAccount](Add-VSTeamAccount.md)
[Remove-VSTeamProject](Remove-VSTeamProject.md)
[Remove-VSTeamProject](Remove-VSTeamProject.md)
[Get-VSTeamProcess](Get-VSTeamProcess.md)
81 changes: 81 additions & 0 deletions .docs/Get-VSTeamProcess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!-- #include "./common/header.md" -->

# Get-VSTeamProcess

## SYNOPSIS

<!-- #include "./synopsis/Get-VSTeamProcess.md" -->

## SYNTAX

## DESCRIPTION

The list of Processs Templates returned can be controlled by using the top and skip parameters.

You can also get a single Process Template by name or id.

You must call Add-VSTeamAccount before calling this function.

## EXAMPLES

### -------------------------- EXAMPLE 1 --------------------------

```PowerShell
PS C:\> Get-VSTeamProcess
```

This will return all the Process Templates

### -------------------------- EXAMPLE 2 --------------------------

```PowerShell
PS C:\> Get-VSTeamProcess -top 5 | Format-Wide
```

This will return the top five Process Templates only showing their name

## PARAMETERS

<!-- #include "./params/ProcessName.md" -->

### -Top

Specifies the maximum number to return.

```yaml
Type: Int32
Parameter Sets: List
Default value: 100
```
### -Skip
Defines the number of Processs Templates to skip. The default value is 0
```yaml
Type: Int32
Parameter Sets: List
Default value: 0
```
### -Id
The id of the Process Template to return.
```yaml
Type: String
Parameter Sets: ByID
Aliases: ProcessID
```
## INPUTS
## OUTPUTS
## NOTES
## RELATED LINKS
[Add-VSTeamAccount](Add-VSTeamAccount.md)
[Add-VSTeamProject](Add-VSTeamProject.md)
12 changes: 12 additions & 0 deletions .docs/params/processName.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### -Name

Specifies the process template name for which this function operates.

You can tab complete from a list of available process templates.

```yaml
Type: String
Required: true
Position: 0
Accept pipeline input: true (ByPropertyName)
```
1 change: 1 addition & 0 deletions .docs/synopsis/Get-VSTeamProcess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Returns a list of process templates in the Team Services or Team Foundation Server account.
3 changes: 3 additions & 0 deletions VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
'src\policies.psm1',
'src\policyTypes.psm1'
'src\pools.psm1',
'src\processes.psm1'
'src\projects.psm1',
'src\queues.psm1',
'src\releaseDefinitions.psm1',
Expand Down Expand Up @@ -142,6 +143,7 @@
'Get-VSTeamPolicy',
'Get-VSTeamPolicyType',
'Get-VSTeamPool',
'Get-VSTeamProcess',
'Get-VSTeamProject',
'Get-VSTeamQueue',
'Get-VSTeamRelease',
Expand Down Expand Up @@ -266,6 +268,7 @@
'Add-GitRepository',
'Remove-GitRepository',
'Get-Pool',
'Get-Process',
'Get-Project',
'Show-Project',
'Update-Project',
Expand Down
108 changes: 108 additions & 0 deletions src/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,114 @@ function _buildProjectNameDynamicParam {
#>
}

function _getProcesses {
if (-not [VSTeamVersions]::Account) {
Write-Output @()
return
}

$resource = "/process/processes"
$instance = [VSTeamVersions]::Account
$version = [VSTeamVersions]::Core

# Build the url to list the projects
# You CANNOT use _buildRequestURI here or you will end up
# in an infinite loop.
$listurl = $instance + '/_apis' + $resource + '?api-version=' + $version + '&stateFilter=All&$top=9999'

# Call the REST API
try {
$resp = _callAPI -url $listurl

if ($resp.count -gt 0) {
Write-Output ($resp.value).name
}
}
catch {
Write-Output @()
}
}
function _buildProcessNameDynamicParam {
param(
[string] $ParameterName = 'ProcessName',
[string] $ParameterSetName,
[bool] $Mandatory = $true,
[string] $AliasName,
[int] $Position = 0
)

# Create the dictionary
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary

# Create the collection of attributes
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

# Create and set the parameters' attributes
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $Mandatory
$ParameterAttribute.Position = $Position

if ($ParameterSetName) {
$ParameterAttribute.ParameterSetName = $ParameterSetName
}

$ParameterAttribute.ValueFromPipelineByPropertyName = $true
$ParameterAttribute.HelpMessage = "The name of the process. You can tab complete from the processes in your Team Services or TFS account when passed on the command line."

# Add the attributes to the attributes collection
$AttributeCollection.Add($ParameterAttribute)

if ($AliasName) {
$AliasAttribute = New-Object System.Management.Automation.AliasAttribute(@($AliasName))
$AttributeCollection.Add($AliasAttribute)
}

# Generate and set the ValidateSet
if($([VSTeamProcessCache]::timestamp) -ne (Get-Date).Minute) {
$arrSet = _getProcesses
[VSTeamProcessCache]::processes = $arrSet
[VSTeamProcessCache]::timestamp = (Get-Date).Minute
}
else {
$arrSet = [VSTeamProcessCache]::projects
}

if ($arrSet) {
Write-Verbose "arrSet = $arrSet"

$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

# Add the ValidateSet to the attributes collection
$AttributeCollection.Add($ValidateSetAttribute)
}

# Create and return the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary

<#
Builds a dynamic parameter that can be used to tab complete the ProjectName
parameter of functions from a list of projects from the added TFS Account.
You must call Add-VSTeamAccount before trying to use any function that relies
on this dynamic parameter or you will get an error.
This can only be used in Advanced Fucntion with the [CmdletBinding()] attribute.
The function must also have a begin block that maps the value to a common variable
like this.
DynamicParam {
# Generate and set the ValidateSet
$arrSet = Get-VSTeamProjects | Select-Object -ExpandProperty Name
_buildProjectNameDynamicParam -arrSet $arrSet
}
process {
# Bind the parameter to a friendly variable
$ProjectName = $PSBoundParameters[$ParameterName]
}
#>
}
function _buildDynamicParam {
param(
[string] $ParameterName = 'QueueName',
Expand Down
75 changes: 75 additions & 0 deletions src/processes.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Set-StrictMode -Version Latest

# Load common code
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$here\common.ps1"

function Get-VSTeamProcess {
[CmdletBinding(DefaultParameterSetName = 'List')]
param(
[Parameter(ParameterSetName = 'List')]
[int] $Top = 100,

[Parameter(ParameterSetName = 'List')]
[int] $Skip = 0,

[Parameter(ParameterSetName = 'ByID')]
[Alias('ProcessTemplateID')]
[string] $Id
)

DynamicParam {
[VSTeamProcessCache]::timestamp = -1

_buildProcessNameDynamicParam -ParameterSetName 'ByName' -ParameterName 'Name'
}

process {
# Bind the parameter to a friendly variable
$ProcessName = $PSBoundParameters["Name"]

if ($id) {
$queryString = @{}

# Call the REST API
$resp = _callAPI -Area 'process/processes' -id $id `
-Version $([VSTeamVersions]::Core) `
-QueryString $queryString

$project = [VSTeamProcess]::new($resp)

Write-Output $project
}
elseif ($ProcessName) {
#Lookup Process ID by Name
Get-VSTeamProcess | where-object {$_.name -eq $ProcessName}

}
else {
#return list of processes
try {
# Call the REST API
$resp = _callAPI -Area 'process/processes' `
-Version $([VSTeamVersions]::Core) `
-QueryString @{
'$top' = $top
'$skip' = $skip
}

$objs = @()

foreach ($item in $resp.value) {
$objs += [VSTeamProcess]::new($item)
}

Write-Output $objs
}
catch {
# I catch because using -ErrorAction Stop on the Invoke-RestMethod
# was still running the foreach after and reporting useless errors.
# This casuses the first error to terminate this execution.
_handleException $_
}
}
}
}
Loading

0 comments on commit 6fdfac0

Please sign in to comment.