Skip to content

Commit a253921

Browse files
🚀 [Feature]: Refactor Connect-GitHubApp to use module version variable and improve parallel processing
1 parent 6454a00 commit a253921

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

‎src/functions/public/Auth/Connect-GitHubApp.ps1‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
$Context = Resolve-GitHubContext -Context $Context
104104
Assert-GitHubContext -Context $Context -AuthType App
105105
$selectedInstallations = @()
106+
$moduleVersion = $script:PSModuleInfo.ModuleVersion
106107
}
107108

108109
process {
@@ -132,23 +133,24 @@
132133

133134
switch ($Installation.Type) {
134135
'User' {
135-
$contextParams['InstallationName'] = [string]$installation.Target.Name
136-
$contextParams['Owner'] = [string]$installation.Target.Name
136+
$contextParams['InstallationName'] = [string]$Installation.Target.Name
137+
$contextParams['Owner'] = [string]$Installation.Target.Name
137138
}
138139
'Organization' {
139-
$contextParams['InstallationName'] = [string]$installation.Target.Name
140-
$contextParams['Owner'] = [string]$installation.Target.Name
140+
$contextParams['InstallationName'] = [string]$Installation.Target.Name
141+
$contextParams['Owner'] = [string]$Installation.Target.Name
141142
}
142143
'Enterprise' {
143-
$contextParams['InstallationName'] = [string]$installation.Target.Name
144-
$contextParams['Enterprise'] = [string]$installation.Target.Name
144+
$contextParams['InstallationName'] = [string]$Installation.Target.Name
145+
$contextParams['Enterprise'] = [string]$Installation.Target.Name
145146
}
146147
}
147148
Write-Verbose 'Logging in using a managed installation access token...'
148149
$contextParams | Format-Table | Out-String -Stream | ForEach-Object { Write-Verbose $_ }
149150
while ($true) {
150151
try {
151152
$contextObj = [GitHubAppInstallationContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default))
153+
break
152154
} catch {
153155
if ($attempts -lt 3) {
154156
$attempts++
@@ -178,9 +180,9 @@
178180
return
179181
}
180182

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
183+
$Installation | ForEach-Object - -ThrottleLimit $ThrottleLimit -UseNewRunspace -Parallel {
184+
Write-Host "Using GitHub $using:moduleVersion"
185+
Import-Module -Name 'GitHub' -RequiredVersion $using:moduleVersion
184186
$params = @{
185187
Installation = $_
186188
Context = $using:Context
@@ -218,7 +220,8 @@
218220
}
219221
}
220222
$selectedInstallations | ForEach-Object -ThrottleLimit $ThrottleLimit -UseNewRunspace -Parallel {
221-
Import-Module -Name 'GitHub' -RequiredVersion $script:PSModuleInfo.ModuleVersion -Force
223+
Write-Host "Using GitHub $using:moduleVersion"
224+
Import-Module -Name 'GitHub' -RequiredVersion $using:moduleVersion
222225
$params = @{
223226
Installation = $_
224227
Context = $using:Context
@@ -234,7 +237,8 @@
234237
Write-Verbose 'No target specified. Connecting to all installations.'
235238
$selectedInstallations = Get-GitHubAppInstallation -Context $Context
236239
$selectedInstallations | ForEach-Object -ThrottleLimit $ThrottleLimit -UseNewRunspace -Parallel {
237-
Import-Module -Name 'GitHub' -RequiredVersion $script:PSModuleInfo.ModuleVersion -Force
240+
Write-Host "Using GitHub $using:moduleVersion"
241+
Import-Module -Name 'GitHub' -RequiredVersion $using:moduleVersion
238242
$params = @{
239243
Installation = $_
240244
Context = $using:Context

0 commit comments

Comments
 (0)