|
81 | 81 | [Parameter()] |
82 | 82 | [switch] $Default, |
83 | 83 |
|
| 84 | + # The maximum number of parallel threads to use when connecting to multiple installations. |
| 85 | + [Parameter()] |
| 86 | + [int] $ThrottleLimit = [System.Environment]::ProcessorCount, |
| 87 | + |
84 | 88 | # The context to run the command in. Used to get the details for the API call. |
85 | 89 | # Can be either a string or a GitHubContext object. |
86 | 90 | [Parameter()] |
|
92 | 96 | Write-Debug "[$stackPath] - Start" |
93 | 97 | $Context = Resolve-GitHubContext -Context $Context |
94 | 98 | Assert-GitHubContext -Context $Context -AuthType App |
| 99 | + $contextObjects = [System.Collections.ArrayList]::new() |
95 | 100 | } |
96 | 101 |
|
97 | 102 | process { |
|
151 | 156 | } |
152 | 157 |
|
153 | 158 | Write-Verbose "Found [$($selectedInstallations.Count)] installations for the target." |
154 | | - $selectedInstallations | ForEach-Object { |
| 159 | + $contextParamList = $selectedInstallations | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel { |
| 160 | + Import-Module -Name $script:PSModuleInfo.Name -RequiredVersion $script:PSModuleInfo.Version -Force -ErrorAction Stop |
155 | 161 | $installation = $_ |
156 | 162 | Write-Verbose "Processing installation [$($installation.Target.Name)] [$($installation.id)]" |
157 | 163 | $token = New-GitHubAppInstallationAccessToken -Context $Context -ID $installation.id |
158 | 164 |
|
159 | 165 | $contextParams = @{ |
160 | 166 | AuthType = [string]'IAT' |
161 | 167 | TokenType = [string]'ghs' |
162 | | - DisplayName = [string]$Context.DisplayName |
163 | | - ApiBaseUri = [string]$Context.ApiBaseUri |
164 | | - ApiVersion = [string]$Context.ApiVersion |
165 | | - HostName = [string]$Context.HostName |
166 | | - HttpVersion = [string]$Context.HttpVersion |
167 | | - PerPage = [int]$Context.PerPage |
168 | | - ClientID = [string]$Context.ClientID |
| 168 | + DisplayName = [string]$using:Context.DisplayName |
| 169 | + ApiBaseUri = [string]$using:Context.ApiBaseUri |
| 170 | + ApiVersion = [string]$using:Context.ApiVersion |
| 171 | + HostName = [string]$using:Context.HostName |
| 172 | + HttpVersion = [string]$using:Context.HttpVersion |
| 173 | + PerPage = [int]$using:Context.PerPage |
| 174 | + ClientID = [string]$using:Context.ClientID |
169 | 175 | InstallationID = [string]$installation.ID |
170 | 176 | Permissions = [GitHubPermission[]]$installation.Permissions |
171 | 177 | Events = [string[]]$installation.Events |
|
188 | 194 | $contextParams['Enterprise'] = [string]$installation.Target.Name |
189 | 195 | } |
190 | 196 | } |
| 197 | + $contextParams |
| 198 | + } |
| 199 | + $contextObjects.AddRange($contextParamList) |
| 200 | + $null = $selectedInstallations.Clear() |
| 201 | + } |
| 202 | + |
| 203 | + end { |
| 204 | + foreach ($contextParams in $contextObjects) { |
191 | 205 | Write-Verbose 'Logging in using a managed installation access token...' |
192 | 206 | $contextParams | Format-Table | Out-String -Stream | ForEach-Object { Write-Verbose $_ } |
193 | 207 | $contextObj = [GitHubAppInstallationContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default)) |
|
204 | 218 | } |
205 | 219 | $contextParams.Clear() |
206 | 220 | } |
207 | | - } |
208 | | - |
209 | | - end { |
210 | 221 | Write-Debug "[$stackPath] - End" |
211 | 222 | } |
212 | 223 | } |
0 commit comments