-
Notifications
You must be signed in to change notification settings - Fork 28
Add ghhelper package for consistent GH_TOKEN/GITHUB_TOKEN handling in gh CLI calls #3977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot look for all instances of the string |
|
@copilot move helper to github.go in pkg/workflow |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new pkg/ghhelper package to centralize GH_TOKEN/GITHUB_TOKEN handling for gh CLI calls, preventing authentication failures when only GITHUB_TOKEN is set. The implementation extracts existing logic from pkg/workflow/gh_helper.go into a standalone package and updates 11 instances across 5 files to use the new helper function.
Key Changes
- New
ghhelper.ExecGH()function provides automatic GH_TOKEN/GITHUB_TOKEN fallback with proper logging - Updated existing
pkg/workflow/gh_helper.goto delegate to the new implementation while maintaining backward compatibility - Replaced direct
exec.Command("gh", ...)calls withghhelper.ExecGH(...)in 5 files for consistent token handling
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/ghhelper/gh_helper.go |
New package providing centralized GH_TOKEN/GITHUB_TOKEN handling for gh CLI commands with proper environment variable precedence and logging |
pkg/ghhelper/gh_helper_test.go |
Comprehensive test coverage for the new helper function, including scenarios for token precedence and multi-argument commands |
pkg/workflow/gh_helper.go |
Simplified to delegate to ghhelper.ExecGH() while maintaining backward compatibility with deprecation notice |
pkg/parser/frontmatter.go |
Updated GitHub file download to use ghhelper.ExecGH() for consistent authentication |
pkg/cli/update_command.go |
Updated 5 instances of gh API calls (releases, branches, content) to use the new helper |
pkg/cli/trial_command.go |
Updated user authentication API call to use the new helper |
pkg/cli/pr_command.go |
Updated 5 instances of gh API calls (user info, permissions, PR info) to use the new helper |
pkg/cli/logs_download.go |
Updated workflow logs and artifact downloads to use the new helper, removed redundant os/exec import |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The codebase had 14 direct
exec.Command("gh", ...)calls that didn't handle GH_TOKEN/GITHUB_TOKEN fallback, causing authentication failures when only GITHUB_TOKEN is set.Changes
pkg/ghhelper: ProvidesExecGH()that automatically sets GH_TOKEN from GITHUB_TOKEN when GH_TOKEN is unsetghhelper.ExecGH():pkg/cli/logs_download.go- workflow logs and artifact downloadspkg/cli/trial_command.go- user authenticationpkg/cli/update_command.go- release/branch/content fetchingpkg/cli/pr_command.go- user permissions and PR infopkg/parser/frontmatter.go- remote file downloadspkg/cli/logs.go- job status and details fetchingpkg/cli/audit.go- run metadata fetchingpkg/workflow/gh_helper.gonow delegates toghhelper.ExecGH()Example
Before:
After:
The helper checks for GH_TOKEN first, falls back to GITHUB_TOKEN if unset, and passes through to default gh auth otherwise.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.