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
Fallback clone from user organization #9044
base: trunk
Are you sure you want to change the base?
Conversation
I can tell you I have clones from multiple organizations and this has bitten me numerous times, too. ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've long wished we had a way to capture an owner for a given directory for those of us who organize based on organization:
cat ~/.config/gh/config.yml
aliases: {}
version: "1"
directoryOwners:
path/to/owner: owner
path/to/owner2: owner2
return err | ||
} | ||
|
||
org, err := promptForOrg(apiClient, repo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do proceed with something like this we need to ensure this only happens if opts.IO.CanPrompt()
is true
. This supports people who aren't using TTY and anyone who has GH_PROMPT_DISABLED
set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially playing around with this I'm not sure about the current approach. The primary concern is that listing the orgs can easily be more confusing or annoying than not. Here's what I experienced: There are two problems here:
I don't think expanding the list of orgs by itself resolves this. It would be nice if we could search within the orgs that the user is a part of and only show those but unless GitHub search supports this (have asked to see if anyone has any ideas) that would involve a lot of network requests as you saw in 9bf322b. |
Maybe there are some heuristics we could apply like:
Would that solve for the most common case, while keeping the request count down? |
@maaslalani how often do you want to clone from |
Yeah I quite like this approach. I would also add one more case, if the org list only contains
Yeah, you're absolutely correct. I like the idea of having a query that can find repositories matching the name of the repo the user tried to clone with different owners so that all the listed options are valid clone-able repositories. So perhaps, we can list repositories from GitHub matching the name and filter by owners that the user has access to. Is there a query for this?
I almost never specify the |
What is the most common use case?
My experience is that people fall into multiple buckets, very rarely just 1. Allowing users to change the default owner might be the best now solution Again, I think the robust solution is enabling users to define the user for a given directory, however that is more work. If we don't want to implement it just yet, it would be easier to iterate on allowing users to change the default owner rather than getting clever on how to find the owner they didn't specify. |
Fixes #2000
This PR solves a problem I generally encounter when cloning repositories. This
is a pretty specific and personal annoyance so feel free to close if it doesn't
fit into the philosophy.
When cloning repositories, I sometimes forget to add the owner:
Then, I receive an error:
Then, I specify the owner and everything is fine:
$ gh repo clone charmbracelet/lipgloss # Cloning into 'lipgloss...'
It would be quite nice if
gh
could clone the repo for me if it knows whichorganizations I generally clone from (the ones I belong to). This PR performs a
fallback to cloning the repository if the user doesn't specify the owner.
So, if a user runs:
The clone will first try
maaslalani/lipgloss
, find that it is not there,then either tries
NixOS/lipgloss
orcharmbracelet/lipgloss
and clonescharmbracelet/lipgloss
since it exists.NB: If the user runs:
$ gh repo clone maaslalani/lipgloss # GraphQL: Could not resolve to a Repository with the name 'maaslalani/lipgloss'. (repository)
They will receive the same error since they explicitly mentioned the
organization they wanted the repository from.
Some improvements to add (if we want to continue with this approach):
2.1.
gh repo clone dotfiles
, repo does exist in user.2.2.
gh repo clone lipgloss
, repo does exist in fallback org.2.3.
gh repo clone obviously-doesnt-exist-anywhere
, repo does not exist anywhere.2.4.
gh repo clone maaslalani/lipgloss
, repo does not exist in explicit owner, but does exist in org.2.5.
gh repo clone charmbracelet/lipgloss
, repo exists in org.2.6.
gh repo clone .github
, repo exists in multiple orgs.