index the tokens per context name for multiple tokens per account - #1
index the tokens per context name for multiple tokens per account#1Propfend wants to merge 2 commits into
Conversation
…ne token. Change active token on the context change even if that is the same accont. Add tests
automationpi
left a comment
There was a problem hiding this comment.
Hey, thanks for the contribution — the use case is real and the code is clean. I tested it locally before reviewing. A few things to fix before I can merge:
1. Broken when GITHUB_TOKEN env var is set (blocking)
Running gh auth login --with-token fails silently in any environment where GITHUB_TOKEN is exported (CI, many dev setups):
The value of the GITHUB_TOKEN environment variable is being used for authentication.
To have GitHub CLI store credentials instead, first clear the value from the environment.
The error is eaten by 2>/dev/null so the user just sees ✗ Failed to apply stored token with no useful message. The fix should either surface that specific error or unset GITHUB_TOKEN before calling gh auth login.
2. Token as a CLI argument exposes it in shell history and ps
gh context set-token --name work ghp_xxx # visible in ~/.bash_history and ps auxPlease accept the token via stdin instead:
echo "ghp_xxx" | gh context set-token --name work
# or prompt interactively with read -rs3. No true per-context token isolation — worth documenting
gh auth login --with-token overwrites the single stored credential for that user@host in gh's keyring — it doesn't create separate slots per context name. Two contexts for the same user with different tokens will work (each switch injects the right token), but there's no isolation at rest. The description implies separate slots exist — worth clarifying this is inject-on-switch, not isolated storage.
4. Tests don't catch issue #1
The mock gh doesn't simulate the GITHUB_TOKEN conflict, so all 40 tests pass even though the real behavior fails in that environment. Would be good to add a test for that path.
Minor: missing newline at end of test/gh-context.bats.
The overall structure is good and I'd like to get this merged — these are fixable issues.
…en it does not exist, cover that with test. Document new funcitonality.
yes, there is isolation at rest, in $CTX_DIR/. Yes, not on the git side, although it would not make a difference on the end user. I have documented that.
Thank you, the changes are done. |
First of all, thanks for the project.
This is more or less what i was looking for. Some tool to change the gh context like that easily, i can see the project can only change accounts for now. I was looking for something that can change the context on per-account basis, like if you have more than one token in the same account, with different permissions. This is useful because by using tools like claude, HCP cloud etc for personal project, you want it to have read-only permission while that is still your personal account. I can see github does not support that natively. So this addresses this issue, by indexing and changing the active token.