Skip to content

Support multiple accounts - #3278

Closed
dantonyuk wants to merge 5 commits into
cli:trunkfrom
dantonyuk:support-multiple-accounts
Closed

dantonyuk wants to merge 5 commits into
cli:trunkfrom
dantonyuk:support-multiple-accounts

Conversation

@dantonyuk

Copy link
Copy Markdown

Now hosts.yml supports user/organization part in a host section name that allows to tune credentials based on a github user or an organization instead of just a host name.

Example:

github.com:
    user: personal-account
    oauth_token: personal-token
github.com/acme:
    user: work-account
    oauth_token: work-token

So when gh is running in the directory related to any repository of acme organization, it will use work-account. In all other cases personal-account will be used. A repository is treated as related to acme organization if git config property remote.origin.url matches one of two forms:

Refer #326

Now hosts.yml supports user/organization part in a host section name
that allows to tune credentials based on a github user or an
organization instead of just a host name.

Example:

```yaml
github.com:
    user: personal-account
    oauth_token: personal-token
github.com/acme:
    user: work-account
    oauth_token: work-token
```

So when `gh` is running in the directory related to any repository of
_acme_ organization, it will use _work-account_. In all other cases
_personal-account_ will be used. A repository is treated as related to
_acme_ organization if git config property `remote.origin.url` matches
one of two forms:

* `[email protected]:acme/repo.git`
* `https://github.com/acme/repo.git`
@ghost

ghost commented Mar 23, 2021

Copy link
Copy Markdown

Will there be any way to indicate who is currently logged on in hosts.yml?

@dantonyuk

Copy link
Copy Markdown
Author

Will there be any way to indicate who is currently logged on in hosts.yml?

Do you mean gh auth status?

@ghost

ghost commented Mar 23, 2021

Copy link
Copy Markdown

Yes

Will there be any way to indicate who is currently logged on in hosts.yml?

Do you mean gh auth status?

@mislav

mislav commented Mar 24, 2021

Copy link
Copy Markdown
Contributor

@dmitry-at-hyla Thank you for this feature! I realize that implementing it might have been tricky since our authentication layer wasn't really built for this kind of on-the-fly switching between the accounts.

We looked at this, but unfortunately we won't pull it at this time since we haven't yet decided if we want switching between multiple users and how it should work. I do not think that username switching will be based on who owns the repository you're currently in, since that leaves the question of which GitHub user should be used for all other repositories. I think that, ultimately, we will have to extend our configuration system with some finer-grained controls.

Anyway, since this is something that we will probably have to do ourselves, we've labeled the original issue core. Per our CONTRIBUTING docs, we currently do not accept PRs for features labelled core.

However, I liked seeing your changeset because it illustrates roughly how much work will be involved in making this feature happen. It might help someone implement this in the future.

@mislav mislav closed this Mar 24, 2021
@dantonyuk

Copy link
Copy Markdown
Author

@F1nx

Yes

Will there be any way to indicate who is currently logged on in hosts.yml?

Do you mean gh auth status?

Well, it's easy to implement. Unfortunately, this PR is rejected. However, I can do this in my fork. Are you interested in that?

@dantonyuk

Copy link
Copy Markdown
Author

@mislav Duly noted.

JFYI: username switching is not based on the owner of the repo, but the user bound to the repo pattern defined in hosts.yml. Anyway, I got your point, there's going to be a lot of work to redesign hosts.yml-related code.

Thank you!

@ghost

ghost commented Mar 25, 2021

Copy link
Copy Markdown

@dmitry-at-hyla I was just checking this PR because it seemed like it passed the checks and would likely be merged.
If it did I'd have to know how to work with the feature in a project I'm working on.

@TheQueenOfHearts90 TheQueenOfHearts90 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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