Skip to content

feat: use GitHub CLI if available to auth instead of GITHUB_TOKEN#694

Open
lukas-preply wants to merge 3 commits intocallstackincubator:mainfrom
lukas-preply:feat/gh-cli-token-fallback
Open

feat: use GitHub CLI if available to auth instead of GITHUB_TOKEN#694
lukas-preply wants to merge 3 commits intocallstackincubator:mainfrom
lukas-preply:feat/gh-cli-token-fallback

Conversation

@lukas-preply
Copy link

Motivation

  • remove the hassle of creating new Github token, which requires setting permissions per repository and in organization with SSO also requires another step to enable SSO for the token. In worst case, if classic token is not allowed, it even requires approval for organization to get access. All this can be solved via GitHub CLI which is usually installed on most developer machines.

Screenshot

  • only have GitHub CLI installed, without GITHUB_TOKEN being set.
image

Summary

This pull request introduces a fallback mechanism for GitHub authentication in the cache provider, allowing the use of the GitHub CLI (gh auth token) when no explicit token or environment variable is available. It also adds comprehensive tests to verify the new logic. The most important changes are grouped below:

Authentication fallback enhancements:

  • Added getGitHubCLIToken function in config.ts to retrieve a GitHub token from the GitHub CLI, falling back when no explicit token or GITHUB_TOKEN environment variable is found.
  • Updated token resolution logic in detectGitHubRepoDetails to prioritize explicit token, then environment variable, then GitHub CLI, improving user experience and flexibility.
  • Modified GitHubBuildCache constructor and getRepoDetails method to defer token resolution and support asynchronous fallback to the GitHub CLI, throwing a clear error if no token is available.

Testing improvements:

  • Added a new test suite in ghCliFallback.test.ts to verify all fallback scenarios, including explicit token, environment variable, GitHub CLI, and error handling when no token is available.

Code organization:

  • Updated imports in providerGitHub.ts to include getGitHubCLIToken for use in the cache provider logic.

Copilot AI and others added 3 commits March 16, 2026 12:36
Co-authored-by: lukas-preply <177529352+lukas-preply@users.noreply.github.com>
feat: add GitHub CLI as fallback for GITHUB_TOKEN
@vercel
Copy link

vercel bot commented Mar 16, 2026

@lukas-preply is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

}
let token = getGitHubToken();
let token =
getGitHubToken() ?? process.env['GITHUB_TOKEN'] ?? (await getGitHubCLIToken());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to include the process.env['GITHUB_TOKEN'] here?

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.

3 participants