Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

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

  • New package pkg/ghhelper: Provides ExecGH() that automatically sets GH_TOKEN from GITHUB_TOKEN when GH_TOKEN is unset
  • Updated 14 instances across 7 files to use ghhelper.ExecGH():
    • pkg/cli/logs_download.go - workflow logs and artifact downloads
    • pkg/cli/trial_command.go - user authentication
    • pkg/cli/update_command.go - release/branch/content fetching
    • pkg/cli/pr_command.go - user permissions and PR info
    • pkg/parser/frontmatter.go - remote file downloads
    • pkg/cli/logs.go - job status and details fetching
    • pkg/cli/audit.go - run metadata fetching
  • Backward compatibility: pkg/workflow/gh_helper.go now delegates to ghhelper.ExecGH()

Example

Before:

cmd := exec.Command("gh", "api", "/user", "--jq", ".login")
output, err := cmd.Output()  // Fails when only GITHUB_TOKEN is set

After:

cmd := ghhelper.ExecGH("api", "/user", "--jq", ".login")
output, err := cmd.Output()  // Works with both GH_TOKEN and GITHUB_TOKEN

The helper checks for GH_TOKEN first, falls back to GITHUB_TOKEN if unset, and passes through to default gh auth otherwise.

Original prompt
  • Add a dedicated exec helper for "gh api ..." calls that handles GH_TOKEN/GITHUB_TOKEN references.
  • Find all instances of "gh api" calls and use new helper.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add exec helper for gh api calls with token handling Add ghhelper package for consistent GH_TOKEN/GITHUB_TOKEN handling in gh CLI calls Nov 14, 2025
Copilot AI requested a review from pelikhan November 14, 2025 17:25
Copilot finished work on behalf of pelikhan November 14, 2025 17:25
@pelikhan
Copy link
Contributor

@copilot look for all instances of the string"api" (with quotes) to find all the calls to gh api and update to use this helper.

@pelikhan
Copy link
Contributor

@copilot move helper to github.go in pkg/workflow

@pelikhan pelikhan marked this pull request as ready for review November 14, 2025 17:37
Copilot AI review requested due to automatic review settings November 14, 2025 17:37
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 14, 2025

@copilot look for all instances of the string"api" (with quotes) to find all the calls to gh api and update to use this helper.

Found and updated 3 additional instances of gh api calls in pkg/cli/logs.go (2 calls) and pkg/cli/audit.go (1 call). All now use ghhelper.ExecGH(). Commit: 7273269

Copilot finished reviewing on behalf of pelikhan November 14, 2025 17:40
Copy link
Contributor

Copilot AI left a 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.go to delegate to the new implementation while maintaining backward compatibility
  • Replaced direct exec.Command("gh", ...) calls with ghhelper.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.

Copilot finished work on behalf of pelikhan November 14, 2025 17:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pelikhan pelikhan merged commit 885b04f into main Nov 14, 2025
10 checks passed
@pelikhan pelikhan deleted the copilot/add-exec-helper-for-gh-api branch November 14, 2025 17:46
Copilot finished work on behalf of pelikhan November 14, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants