Skip to content

Commit ca25ebd

Browse files
chidozieononiwuazure-sdk
authored andcommitted
Update fetching of installation ID
1 parent 9091805 commit ca25ebd

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

eng/common/pipelines/templates/steps/create-tags-and-git-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ steps:
1515
- template: /eng/common/pipelines/templates/steps/login-to-github.yml
1616
parameters:
1717
TokenOwners:
18-
- ${{ split(parameters.RepoId, '/')[0] }}
18+
- ${{ parameters.RepoId }}
1919
ScriptDirectory: ${{ parameters.ScriptDirectory }}
2020

2121
- task: PowerShell@2

eng/common/scripts/login-to-github.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function Get-GitHubInstallationId {
131131
$resp | Foreach-Object { Write-Host " $($_.id): $($_.account.login) [$($_.target_type)]" }
132132

133133
$resp = $resp | Where-Object { $_.account.login -ieq $InstallationTokenOwner }
134-
if (!$resp.id) { throw "No installations found for this App." }
134+
if ($null -eq $resp -or !$resp.id) { throw "No installation found for '$InstallationTokenOwner' in this App. Verify the App is installed on that org/user." }
135135
return $resp.id
136136
}
137137

@@ -154,8 +154,10 @@ $jwt = New-GitHubAppJwt -VaultName $KeyVaultName -KeyName $KeyName -AppId $GitHu
154154

155155
foreach ($InstallationTokenOwner in $InstallationTokenOwners)
156156
{
157-
Write-Host "Fetching installation ID for $InstallationTokenOwner ..."
158-
$installationId = Get-GitHubInstallationId -Jwt $jwt -ApiBase $GitHubApiBaseUrl -ApiVersion $GitHubApiVersion -InstallationTokenOwner $InstallationTokenOwner
157+
# Token owners can be provided as either "owner" or "owner/repo". Normalize to owner.
158+
$normalizedOwner = ($InstallationTokenOwner -split '/')[0]
159+
Write-Host "Fetching installation ID for $InstallationTokenOwner (normalized owner: $normalizedOwner) ..."
160+
$installationId = Get-GitHubInstallationId -Jwt $jwt -ApiBase $GitHubApiBaseUrl -ApiVersion $GitHubApiVersion -InstallationTokenOwner $normalizedOwner
159161

160162
Write-Host "Installation ID resolved: $installationId"
161163

@@ -165,7 +167,7 @@ foreach ($InstallationTokenOwner in $InstallationTokenOwners)
165167
$variableName = $VariableNamePrefix
166168
if ($InstallationTokenOwners.Count -gt 1)
167169
{
168-
$variableName = $VariableNamePrefix + "_" + $InstallationTokenOwner
170+
$variableName = $VariableNamePrefix + "_" + $normalizedOwner
169171
}
170172

171173
Set-Item -Path Env:$variableName -Value $installationToken

0 commit comments

Comments
 (0)