Quick fix: respect default hostname when parsing owner/repo pairs
This re-enables using GH_HOST to set a default hostname when supplying repo argument like `gh repo clone owner/repo`.
This commit is contained in:
parent
815ae7a22d
commit
69ca2dda4a
2 changed files with 23 additions and 2 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/cli/cli/internal/build"
|
||||
"github.com/cli/cli/internal/config"
|
||||
"github.com/cli/cli/internal/ghinstance"
|
||||
"github.com/cli/cli/internal/ghrepo"
|
||||
"github.com/cli/cli/internal/run"
|
||||
"github.com/cli/cli/internal/update"
|
||||
"github.com/cli/cli/pkg/cmd/alias/expand"
|
||||
|
|
@ -100,6 +101,11 @@ func mainRun() exitCode {
|
|||
cmdFactory.IOStreams.SetPager(pager)
|
||||
}
|
||||
|
||||
// TODO: remove after FromFullName has been revisited
|
||||
if host, err := cfg.DefaultHost(); err == nil {
|
||||
ghrepo.SetDefaultHost(host)
|
||||
}
|
||||
|
||||
expandedArgs := []string{}
|
||||
if len(os.Args) > 0 {
|
||||
expandedArgs = os.Args[1:]
|
||||
|
|
|
|||
|
|
@ -35,6 +35,21 @@ func FullName(r Interface) string {
|
|||
return fmt.Sprintf("%s/%s", r.RepoOwner(), r.RepoName())
|
||||
}
|
||||
|
||||
var defaultHostOverride string
|
||||
|
||||
func defaultHost() string {
|
||||
if defaultHostOverride != "" {
|
||||
return defaultHostOverride
|
||||
}
|
||||
return ghinstance.Default()
|
||||
}
|
||||
|
||||
// SetDefaultHost overrides the default GitHub hostname for FromFullName.
|
||||
// TODO: remove after FromFullName approach is revisited
|
||||
func SetDefaultHost(host string) {
|
||||
defaultHostOverride = host
|
||||
}
|
||||
|
||||
// FromFullName extracts the GitHub repository information from the following
|
||||
// formats: "OWNER/REPO", "HOST/OWNER/REPO", and a full URL.
|
||||
func FromFullName(nwo string) (Interface, error) {
|
||||
|
|
@ -54,9 +69,9 @@ func FromFullName(nwo string) (Interface, error) {
|
|||
}
|
||||
switch len(parts) {
|
||||
case 3:
|
||||
return NewWithHost(parts[1], parts[2], normalizeHostname(parts[0])), nil
|
||||
return NewWithHost(parts[1], parts[2], parts[0]), nil
|
||||
case 2:
|
||||
return New(parts[0], parts[1]), nil
|
||||
return NewWithHost(parts[0], parts[1], defaultHost()), nil
|
||||
default:
|
||||
return nil, fmt.Errorf(`expected the "[HOST/]OWNER/REPO" format, got %q`, nwo)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue