You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Centralizes the repeated gh token environment logic.
New packages/host/src/gh-env.ts owns the host classification and token keys:
github.com + *.ghe.com → GH_TOKEN / GITHUB_TOKEN
GitHub Enterprise Server → GH_ENTERPRISE_TOKEN / GITHUB_ENTERPRISE_TOKEN
host.ts account selection now uses clearInheritedTokens, tokenKeys, and setHostToken instead of three copies of the same delete/set blocks.
gh.ts action execution uses setHostToken too, which fixes GHES actions that previously set the ignored GH_TOKEN.
Regression test covers a GHES action using GH_ENTERPRISE_TOKEN.
yarn check: 653/653.
No behavior change for github.com or Enterprise Cloud.
Summary by CodeRabbit
Bug Fixes
GitHub CLI actions now use the appropriate token environment variable for the selected host, including enterprise hosts.
Host account selection now applies the matching token for GitHub.com or an enterprise host and clears inherited GitHub token variables to prevent conflicting credentials.
No actionable comments were generated in the recent review.
Walkthrough
The change centralizes host classification and GitHub token environment handling. Host account handling and gh action execution use the shared helpers. A GHES-host test checks the enterprise token variable.
Changes: Host-aware token environment
Layer / File(s)
Summary
Host classification and token helpers packages/host/src/gh-env.ts
Adds host classification and host-specific token keys. Adds helpers to clear all four token variables and set the token key selected for a host.
Host and gh token integration packages/host/src/commands/host.ts, packages/host/src/gh.ts, test/unit/gh.test.ts, .changeset/gh-token-env.md
Host account handling uses the shared helpers to check, clear, and set tokens. For runGhAction invocations without --jq, token setup uses setHostToken; the --jq path is unchanged. Adds a GHES-host test and a patch changeset.
code-vaults/git-credential-broker#40: Changes the --jq token path in the same runGhAction function that this PR updates for invocations without --jq.
Suggested reviewers:i1stg
Merge Risk: Minimal · up to 345c2
This change makes GitHub Enterprise Server actions use the correct enterprise token variable, with no behavior change for github.com or Enterprise Cloud. No merge-blocking risk was identified.
Security architecture risk: Low · up to 345c2
Credential selection changes for Enterprise Server actions, while existing host restrictions, repository authorization, and per-invocation credential isolation remain in place. No introduced security bypass was identified. Compatibility with a deployed GitHub CLI was not exercised.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
observed — The changed credential delivery reaches the existing GitHub action subprocess. Installation-token requests remain restricted to the requested repository and action permissions; user-identity actions use the separately authorized personal token. These upstream token-selection branches are unchanged by the PR.
Trust Boundaries and Controls
observed — The existing broker rejects requests without a configured host, selects the provider using that configured host, and checks repository eligibility, action arguments, configured denials, and identity support before execution. These controls counter the concern that choosing the Enterprise token variable creates an unrestricted caller-selected credential destination.
Resilience and Maintainability Implications
observed — The action runner retains its existing timeout, output-limit, process-group termination, and temporary-directory cleanup paths. The provider attempts installation-token revocation in finally after action execution, preserving its warning behavior when revocation fails.
observed — The new Enterprise Server regression test asserts that the subprocess receives GH_ENTERPRISE_TOKEN. It uses a shell shim, demonstrating environment assignment rather than actual GitHub CLI authentication behavior. Tests were inspected, not executed during this assessment.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "refactor: centralize gh token environment handling" matches the main change. The PR adds gh-env.ts, which centralizes host classification and GitHub CLI token-key selection, and updates hos…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "refactor: centralize gh token environment handling" matches the main change. The PR adds gh-env.ts, which centralizes host classification and GitHub CLI token-key selection, and updates host.ts and gh.ts to use the shared helpers. The title is concise, uses a conventional type prefix, and avoids vague terms. The title does not mention the GHES fix (GH_ENTERPRISE_TOKEN for GHES actions), but the title does not need to cover every detail.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 7ce62193-b18f-4190-99cf-eae081bc16b6
Commits
Reviewing files that changed from the base of the PR and between 686b638 and 345c2f3.
Files selected for processing: 5
.changeset/gh-token-env.md
packages/host/src/commands/host.ts
packages/host/src/gh-env.ts
packages/host/src/gh.ts
test/unit/gh.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
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
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.
Centralizes the repeated gh token environment logic.
packages/host/src/gh-env.tsowns the host classification and token keys:github.com+*.ghe.com→GH_TOKEN/GITHUB_TOKENGH_ENTERPRISE_TOKEN/GITHUB_ENTERPRISE_TOKENhost.tsaccount selection now usesclearInheritedTokens,tokenKeys, andsetHostTokeninstead of three copies of the same delete/set blocks.gh.tsaction execution usessetHostTokentoo, which fixes GHES actions that previously set the ignoredGH_TOKEN.GH_ENTERPRISE_TOKEN.yarn check: 653/653.No behavior change for github.com or Enterprise Cloud.
Summary by CodeRabbit