|
59 | 59 | [string[]] $Enterprise,
|
60 | 60 |
|
61 | 61 | # Installation objects from pipeline for parallel processing.
|
62 |
| - [Parameter(Mandatory, ParameterSetName = 'Installation', ValueFromPipeline)] |
| 62 | + [Parameter(Mandatory, ParameterSetName = 'Installation object', ValueFromPipeline)] |
63 | 63 | [GitHubAppInstallation[]] $Installation,
|
64 | 64 |
|
| 65 | + # The installation ID(s) to connect to directly. |
| 66 | + # Accepts input from the pipeline by property name (e.g. objects with an ID property) |
| 67 | + [Parameter(Mandatory, ParameterSetName = 'Installation ID', ValueFromPipelineByPropertyName)] |
| 68 | + [Alias('InstallationID')] |
| 69 | + [int[]] $ID, |
| 70 | + |
65 | 71 | # Passes the context object to the pipeline.
|
66 | 72 | [Parameter()]
|
67 | 73 | [switch] $PassThru,
|
|
89 | 95 | }
|
90 | 96 |
|
91 | 97 | process {
|
92 |
| - $installations = Get-GitHubAppInstallation -Context $Context |
93 |
| - $selectedInstallations = @() |
94 |
| - Write-Verbose "Found [$($installations.Count)] installations." |
| 98 | + $selectedInstallations = [System.Collections.ArrayList]::new() |
95 | 99 | switch ($PSCmdlet.ParameterSetName) {
|
96 | 100 | 'Filtered' {
|
| 101 | + $installations = Get-GitHubAppInstallation -Context $Context |
| 102 | + Write-Verbose "Found [$($installations.Count)] installations." |
97 | 103 | $User | ForEach-Object {
|
98 | 104 | $userItem = $_
|
99 | 105 | Write-Verbose "User filter: [$userItem]."
|
100 |
| - $selectedInstallations += $installations | Where-Object { |
101 |
| - $_.Type -eq 'User' -and $_.Target.Name -like $userItem |
| 106 | + $installations | Where-Object { $_.Type -eq 'User' -and $_.Target.Name -like $userItem } | ForEach-Object { |
| 107 | + $null = $selectedInstallations.Add($_) |
102 | 108 | }
|
103 | 109 | }
|
104 | 110 | $Organization | ForEach-Object {
|
105 | 111 | $organizationItem = $_
|
106 | 112 | Write-Verbose "Organization filter: [$organizationItem]."
|
107 |
| - $selectedInstallations += $installations | Where-Object { |
108 |
| - $_.Type -eq 'Organization' -and $_.Target.Name -like $organizationItem |
| 113 | + $installations | Where-Object { $_.Type -eq 'Organization' -and $_.Target.Name -like $organizationItem } | ForEach-Object { |
| 114 | + $null = $selectedInstallations.Add($_) |
109 | 115 | }
|
110 | 116 | }
|
111 | 117 | $Enterprise | ForEach-Object {
|
112 | 118 | $enterpriseItem = $_
|
113 | 119 | Write-Verbose "Enterprise filter: [$enterpriseItem]."
|
114 |
| - $selectedInstallations += $installations | Where-Object { |
115 |
| - $_.Type -eq 'Enterprise' -and $_.Target.Name -like $enterpriseItem |
| 120 | + $installations | Where-Object { $_.Type -eq 'Enterprise' -and $_.Target.Name -like $enterpriseItem } | ForEach-Object { |
| 121 | + $null = $selectedInstallations.Add($_) |
| 122 | + } |
| 123 | + } |
| 124 | + break |
| 125 | + } |
| 126 | + 'Installation ID' { |
| 127 | + Write-Verbose 'Selecting installations by explicit ID.' |
| 128 | + foreach ($installationId in $ID) { |
| 129 | + Write-Verbose "Looking up installation ID [$installationId]" |
| 130 | + $found = Get-GitHubAppInstallation -ID $installationId -Context $Context |
| 131 | + if (-not $found) { |
| 132 | + Write-Warning "No installation found for ID [$installationId]." |
| 133 | + continue |
116 | 134 | }
|
| 135 | + $null = $selectedInstallations.Add($found) |
| 136 | + } |
| 137 | + break |
| 138 | + } |
| 139 | + 'Installation object' { |
| 140 | + Write-Verbose 'Selecting installations from the pipeline.' |
| 141 | + foreach ($installationObject in $Installation) { |
| 142 | + $null = $selectedInstallations.Add($installationObject) |
117 | 143 | }
|
| 144 | + break |
118 | 145 | }
|
119 | 146 | default {
|
120 | 147 | Write-Verbose 'No target specified. Connecting to all installations.'
|
121 |
| - $selectedInstallations = $installations |
| 148 | + $selectedInstallations.AddRange((Get-GitHubAppInstallation -Context $Context)) |
| 149 | + Write-Verbose "Found [$($selectedInstallations.Count)] installations." |
122 | 150 | }
|
123 | 151 | }
|
124 | 152 |
|
|
0 commit comments