Repository navigation
Add repository-scoped auth mapping and repo-aware status - #12681
awakecoding wants to merge 2 commits into
Conversation
|
Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message. |
There was a problem hiding this comment.
Pull request overview
This pull request adds repository-scoped account selection to GitHub CLI, enabling users to work with multiple GitHub accounts on the same host without manually switching the global active account. The implementation includes a new gh auth map command group for managing repository-to-account mappings, dynamic token selection during API requests based on repository context, and enhanced gh auth status output that displays the effective account for the current repository.
Changes:
- Added
gh auth map {set,list,remove}commands to configure per-repository or per-owner account mappings - Implemented dynamic token getter that resolves repository context from git remotes and applies mappings transparently during API requests
- Enhanced
gh auth statusto display current repository authentication information when available
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/cmd/auth/map/map.go |
New command implementation for managing repository account mappings with support for owner/* and owner/repo scopes |
pkg/cmd/auth/map/map_test.go |
Test coverage for map command parsing and CRUD operations |
pkg/cmd/auth/auth.go |
Integration of new map command into auth command group |
pkg/cmd/auth/status/status.go |
Added repository-aware status display showing effective account and source |
pkg/cmd/auth/status/status_test.go |
Test coverage for repository status display with mapped and unmapped scenarios |
pkg/cmd/factory/dynamic_token_getter.go |
Token selection logic that applies repository mappings when resolving API credentials |
pkg/cmd/factory/dynamic_token_getter_test.go |
Tests verifying mapping-based token selection and environment token precedence |
pkg/cmd/factory/default.go |
HTTP client factory integration to use dynamic token getter with repository context |
internal/config/config.go |
Config layer methods for storing/retrieving repository-to-user mappings with case-insensitive owner/repo matching |
internal/config/auth_config_test.go |
Config layer test coverage for mapping CRUD operations and lookup priority |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thank you for your contribution! Unfortunately, this pull request is not linked to a We encourage community contributions on issues labeled
help wanted
If you believe this was done in error, please let us know. |
|
@BagToad I understand the need to link pull requests to issues, but I did link it to #12459 There's a real need for automatic account selection. The other issue suggests mapping it to the git configuration which I'd be happy to implement as well, even though my implementation does the mapping independently from git. I'm just looking for the best place to discuss the issue to be addressed and come up with an accepted change to implement it, regardless of the chosen implementation. The lack of dynamic account selection in GitHub CLI is a huge pain point when using multiple accounts concurrently, and apparently I'm not the only one facing this issue. I'd appreciate guidance on the right process to open the right issue to describe the problem, and then discuss the right way to implement the feature. Should I open a new issue if I think it should not necessarily be tied to the underlying SSH configuration? One doesn't prevent the other, so maybe we can do both. |
|
Argh. Unrelated to GithHub CLI, but I obviously forgot to switch accounts on the GitHub mobile app before replying. If you have to think of switching, you're repeated going to forget to do it. |
|
Hey @awakecoding, I saw this come in over the weekend and I had a glance at your blog post. It looks like you'd done a lot of investigation already, so I think it would be great to try and keep some momentum here. I've really wanted to continue working on better multi account support since I first introduced It's fine if that discussion's starting point is really just "hey, I have these issues (see my blog post), and I created this PR, let's continue the discussion" - I just want a place for us to continue. |
|
@williammartin I'm willing to do the required work to come up with a decent solution that satisfies everyone, as this is a huge pain point for me (and apparently others). I opened a new discussion with a summary of my approach with an extension to include leveraging git ssh configuration if we want to include that improvement done by others as well: #12697 |
Summary
This PR adds repository-scoped account selection to GitHub CLI so users can work across multiple accounts on the same host without repeatedly running a global
gh auth switch.It also updates
gh auth statusto show the effective account for the current repository while preserving existing global host/account status output.Fixes #12459 and #12628 in a slightly different way than suggested. I prefer the current approach as it does not rely on external SSH configuration. The auth mapping mechanism is simple and works at the GitHub CLI level. A few simple mapping rules should do the trick to eliminate issues when using multiple GitHub accounts at the same time.
Motivation
This addresses multi-account workflow friction described in:
In short: git/SSH can already route identities per repo/org, but
ghpreviously required manual global account switching.What changed
1) Repository account mappings
Added a new command group:
gh auth map set <scope> --user <login>gh auth map list [--hostname <host>]gh auth map remove <scope>Supported scopes:
OWNER/*OWNER/REPOHOST/OWNER/*HOST/OWNER/REPOMatching behavior:
owner/repo)owner/*)Environment token precedence is preserved (
GH_TOKEN,GITHUB_TOKEN, etc.).2) Dynamic token selection during API requests
ghnow resolves a repository context from remotes and applies repository mapping when selecting a token for API requests, instead of requiring global active-user mutation.3) Repository-aware auth status
gh auth statusnow prints a concise current-repository summary:repository mapping,active host account, orenvironment token)Global host/account sections remain unchanged below the summary.
Example
Validation
go test ./internal/config ./pkg/cmd/factory ./pkg/cmd/auth/map ./pkg/cmd/auth/statusgo build ./...Notes
gh auth switchbehavior is unchanged.