Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple accounts #3278

Closed
wants to merge 5 commits into from

Conversation

dantonyuk
Copy link

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:

  • git@github.com:acme/repo.git
  • https://github.com/acme/repo.git

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:

* `git@github.com:acme/repo.git`
* `https://github.com/acme/repo.git`
@ghost
Copy link

ghost commented Mar 23, 2021

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

@dantonyuk
Copy link
Author

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

Do you mean gh auth status?

@ghost
Copy link

ghost commented Mar 23, 2021

Yes

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

Do you mean gh auth status?

@mislav
Copy link
Contributor

mislav commented Mar 24, 2021

@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
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
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
Copy link

ghost commented Mar 25, 2021

@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.

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.

None yet

2 participants