Skip to content

Commit 7b2af37

Browse files
committed
feat: Add token scope validation
Checks token scopes using x-oauth-scopes header: - Reports scopes for classic PATs - Warns if repo/public_repo scope missing - Provides guidance for fine-grained PATs Based on https://github.com/orgs/community/discussions/25259
1 parent 71c67c5 commit 7b2af37

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

updater/action.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ runs:
132132
exit 1
133133
}
134134
135+
# Check token validity and access
135136
gh api repos/${{ github.repository }} --silent 2>&1 | Out-Null
136137
if ($LASTEXITCODE -ne 0) {
137138
Write-Output "::error::GitHub token validation failed. Please verify:"
@@ -142,6 +143,24 @@ runs:
142143
Write-Output " 5. Token syntax is correct: "'${{ secrets.TOKEN_NAME }}'"
143144
exit 1
144145
}
146+
147+
# Check token scopes (works for classic PATs only)
148+
$headers = curl -sS -I -H "Authorization: token $env:GH_TOKEN" https://api.github.com 2>&1
149+
$scopeLine = $headers | Select-String -Pattern '^x-oauth-scopes:' -CaseSensitive:$false
150+
if ($scopeLine) {
151+
$scopes = $scopeLine -replace '^x-oauth-scopes:\s*', '' -replace '\r', ''
152+
if ([string]::IsNullOrWhiteSpace($scopes)) {
153+
Write-Output "::warning::Token has no scopes. If using a fine-grained PAT, ensure it has Contents (write) and Pull Requests (write) permissions."
154+
} else {
155+
Write-Output "Token scopes: $scopes"
156+
if ($scopes -notmatch '\brepo\b' -and $scopes -notmatch '\bpublic_repo\b') {
157+
Write-Output "::warning::Token may be missing 'repo' or 'public_repo' scope. This may cause issues with private repositories."
158+
}
159+
}
160+
} else {
161+
Write-Output "::notice::Could not detect token scopes (this is normal for fine-grained PATs). Ensure token has Contents (write) and Pull Requests (write) permissions."
162+
}
163+
145164
Write-Output "✓ GitHub token is valid and has access to this repository"
146165
147166
- name: Configure git credentials

0 commit comments

Comments
 (0)