|
122 | 122 | HttpVersion = [string]$Context.HttpVersion |
123 | 123 | PerPage = [int]$Context.PerPage |
124 | 124 | ClientID = [string]$Context.ClientID |
125 | | - InstallationID = [string]$installation.ID |
126 | | - Permissions = [GitHubPermission[]]$installation.Permissions |
127 | | - Events = [string[]]$installation.Events |
128 | | - InstallationType = [string]$installation.Type |
| 125 | + InstallationID = [string]$Installation.ID |
| 126 | + Permissions = [GitHubPermission[]]$Installation.Permissions |
| 127 | + Events = [string[]]$Installation.Events |
| 128 | + InstallationType = [string]$Installation.Type |
129 | 129 | Token = [securestring]$token.Token |
130 | 130 | TokenExpiresAt = [datetime]$token.ExpiresAt |
131 | 131 | } |
132 | 132 |
|
133 | | - switch ($installation.Type) { |
| 133 | + switch ($Installation.Type) { |
134 | 134 | 'User' { |
135 | 135 | $contextParams['InstallationName'] = [string]$installation.Target.Name |
136 | 136 | $contextParams['Owner'] = [string]$installation.Target.Name |
|
146 | 146 | } |
147 | 147 | Write-Verbose 'Logging in using a managed installation access token...' |
148 | 148 | $contextParams | Format-Table | Out-String -Stream | ForEach-Object { Write-Verbose $_ } |
149 | | - $contextObj = [GitHubAppInstallationContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default)) |
| 149 | + while ($true) { |
| 150 | + try { |
| 151 | + $contextObj = [GitHubAppInstallationContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default)) |
| 152 | + } catch { |
| 153 | + if ($attempts -lt 3) { |
| 154 | + $attempts++ |
| 155 | + Write-Warning "Failed to create context. Retrying... [$attempts]" |
| 156 | + Start-Sleep -Seconds (1 * $attempts) |
| 157 | + } else { |
| 158 | + throw $_ |
| 159 | + } |
| 160 | + } |
| 161 | + } |
150 | 162 | $contextObj | Format-List | Out-String -Stream | ForEach-Object { Write-Verbose $_ } |
151 | 163 | if (-not $Silent) { |
152 | 164 | $name = $contextObj.Name |
|
166 | 178 | return |
167 | 179 | } |
168 | 180 |
|
169 | | - $Installation | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel { |
| 181 | + $Installation | ForEach-Object -ThrottleLimit $ThrottleLimit -UseNewRunspace -Parallel { |
| 182 | + Write-Host "Using GitHub $($script:PSModuleInfo.ModuleVersion)" |
| 183 | + Import-Module -Name 'GitHub' -RequiredVersion $script:PSModuleInfo.ModuleVersion |
170 | 184 | $params = @{ |
171 | | - ID = $_.ID |
172 | | - Context = $using:Context |
173 | | - PassThru = $using:PassThru |
174 | | - Silent = $using:Silent |
175 | | - Default = $using:Default |
| 185 | + Installation = $_ |
| 186 | + Context = $using:Context |
| 187 | + PassThru = $using:PassThru |
| 188 | + Silent = $using:Silent |
| 189 | + Default = $using:Default |
176 | 190 | } |
177 | 191 | Connect-GitHubApp @params |
178 | 192 | } |
|
203 | 217 | $_.Type -eq 'Enterprise' -and $_.Target.Name -like $enterpriseItem |
204 | 218 | } |
205 | 219 | } |
206 | | - $selectedInstallations | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel { |
| 220 | + $selectedInstallations | ForEach-Object -ThrottleLimit $ThrottleLimit -UseNewRunspace -Parallel { |
| 221 | + Import-Module -Name 'GitHub' -RequiredVersion $script:PSModuleInfo.ModuleVersion -Force |
207 | 222 | $params = @{ |
208 | | - ID = $_.ID |
209 | | - Context = $using:Context |
210 | | - PassThru = $using:PassThru |
211 | | - Silent = $using:Silent |
212 | | - Default = $using:Default |
| 223 | + Installation = $_ |
| 224 | + Context = $using:Context |
| 225 | + PassThru = $using:PassThru |
| 226 | + Silent = $using:Silent |
| 227 | + Default = $using:Default |
213 | 228 | } |
214 | 229 | Connect-GitHubApp @params |
215 | 230 | } |
|
218 | 233 | 'All Installations' { |
219 | 234 | Write-Verbose 'No target specified. Connecting to all installations.' |
220 | 235 | $selectedInstallations = Get-GitHubAppInstallation -Context $Context |
221 | | - $selectedInstallations | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel { |
| 236 | + $selectedInstallations | ForEach-Object -ThrottleLimit $ThrottleLimit -UseNewRunspace -Parallel { |
| 237 | + Import-Module -Name 'GitHub' -RequiredVersion $script:PSModuleInfo.ModuleVersion -Force |
222 | 238 | $params = @{ |
223 | | - ID = $_.ID |
224 | | - Context = $using:Context |
225 | | - PassThru = $using:PassThru |
226 | | - Silent = $using:Silent |
227 | | - Default = $using:Default |
| 239 | + Installation = $_ |
| 240 | + Context = $using:Context |
| 241 | + PassThru = $using:PassThru |
| 242 | + Silent = $using:Silent |
| 243 | + Default = $using:Default |
228 | 244 | } |
229 | 245 | Connect-GitHubApp @params |
230 | 246 | } |
|
0 commit comments