Skip to content

Commit 8f94994

Browse files
Retry Install-GitHubApp on enterprise organization to absorb propagation delay (#596)
1 parent 9da0e0a commit 8f94994

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

tests/Organizations.Tests.ps1

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,24 @@ Describe 'Organizations' {
143143
}
144144

145145
It 'Install-GitHubApp - Installs a GitHub App to an organization' -Skip:($OwnerType -ne 'enterprise') {
146-
$installation = Install-GitHubApp -Enterprise $owner -Organization $orgName -ClientID $installationContext.ClientID -RepositorySelection 'all'
146+
# The enterprise organization was just created and may not have propagated to the
147+
# enterprise apps endpoint yet. Retry briefly to absorb propagation delay before
148+
# failing — GitHub returns 404 (rather than 403) when the resource is not yet visible
149+
# to the token, which is indistinguishable from a missing-permission failure on the
150+
# first call. See issue #596.
151+
$installation = $null
152+
$maxAttempts = 5
153+
$delaySeconds = 3
154+
for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
155+
try {
156+
$installation = Install-GitHubApp -Enterprise $owner -Organization $orgName -ClientID $installationContext.ClientID -RepositorySelection 'all'
157+
break
158+
} catch {
159+
if ($attempt -eq $maxAttempts) { throw }
160+
Write-Host "Install-GitHubApp attempt $attempt failed ($($_.Exception.Message)); retrying in $delaySeconds seconds..."
161+
Start-Sleep -Seconds $delaySeconds
162+
}
163+
}
147164
LogGroup 'Installed App' {
148165
Write-Host ($installation | Select-Object * | Out-String)
149166
}

0 commit comments

Comments
 (0)