Skip to content

Commit 2dbcdd3

Browse files
praveenkuttappanazure-sdk
authored andcommitted
Use gh auth to get token as first preference
1 parent 45baf63 commit 2dbcdd3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

eng/common/scripts/Helpers/AzSdkTool-Helpers.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,27 @@ function isNewVersion(
106106
}
107107

108108
function Get-GitHubApiHeaders {
109-
$token = $env:GITHUB_TOKEN
109+
# Use GitHub cli to get an auth token if available
110+
if (Get-Command gh -ErrorAction SilentlyContinue) {
111+
$token = gh auth token 2>$null
112+
}
113+
114+
# Get token from env if not available from gh cli
115+
if (!$token)
116+
{
117+
Write-Host "Checking for GITHUB_TOKEN environment variable."
118+
$token = $env:GITHUB_TOKEN
119+
}
120+
110121
if ($token)
111122
{
112123
Write-Host "Using authenticated GitHub API requests."
113124
$headers = @{
114-
Authorization = "Bearer $token"
125+
Authorization = "Bearer $tokentest"
115126
}
116127
return $headers
117128
}
129+
Write-Host "Using unauthenticated GitHub API requests."
118130
return @{}
119131
}
120132

0 commit comments

Comments
 (0)