Adopt isPermissionError helper for gh CLI auth-error detection#32758
Merged
Conversation
4 tasks
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Adopt isPermissionError helper for gh CLI auth-error detection
Adopt isPermissionError helper for gh CLI auth-error detection
May 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes GitHub CLI authentication and permission-error detection helpers across several pkg/cli call sites.
Changes:
- Extracts string-based permission detection and adds a shared 403 helper.
- Replaces inline auth/403 substring checks in logs and secrets flows.
- Extends helper unit tests for additional auth and 403 cases.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/audit.go |
Adds shared string/error permission helpers and 403 detection. |
pkg/cli/audit_test.go |
Adds coverage for new helper behavior. |
pkg/cli/logs_github_api.go |
Uses the shared auth helper for workflow-run listing failures. |
pkg/cli/logs_download.go |
Uses the shared auth helper for log/artifact download failures. |
pkg/cli/mcp_secrets.go |
Uses the shared 403 helper for skipped secret checks. |
pkg/cli/secrets.go |
Uses the shared 403 helper in secret availability checks. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 3
| strings.Contains(combinedMsg, "To use GitHub CLI in a GitHub Actions workflow") || | ||
| strings.Contains(combinedMsg, "authentication required") || | ||
| strings.Contains(outputMsg, "gh auth login") { | ||
| if isPermissionErrorStr(combinedMsg) { |
Comment on lines
+112
to
114
| // If we get a 403 error, skip silently (no permission to check) | ||
| if is403Error(err) { | ||
| continue |
| }, | ||
| { | ||
| name: "GitHub Actions workflow auth error", | ||
| err: errors.New("To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four call sites in
pkg/cliwere reimplementing auth-error substring checks inline instead of using the existingisPermissionErrorhelper inaudit.go, causing the checked substring sets to drift independently across files.Changes
pkg/cli/audit.goisPermissionErrorinto an internalisPermissionErrorStr(s string) boolthat operates on raw strings (enabling callers that check combined error+output messages) and a thinisPermissionError(err error) boolwrapper"not logged into any GitHub hosts","To use GitHub CLI in a GitHub Actions workflow", and"gh auth login"(previously only checked inline inlogs_github_api.go)is403Error(err error) boolfor 403 HTTP status checksCall site consolidation
logs_download.go(×2):strings.Contains(err.Error(), "exit status 4")→isPermissionError(err)logs_github_api.go: five-clause inline auth check →isPermissionErrorStr(combinedMsg)(preserves combined error+output matching)secrets.go,mcp_secrets.go:strings.Contains(err.Error(), "403")→is403Error(err)secrets.go: fixes inverted 403 guard logic (!is403Error→is403Error) to match the comment's stated intentBefore / After (
logs_download.go)Tests
TestIsPermissionErrorwith the three new substringsTestIsPermissionErrorStrcovering the string-based helperTestIs403Error