зеркало из https://github.com/mislav/hub.git
Rename Host to GitHubHost to be explicit
This commit is contained in:
Родитель
b70cb9d7de
Коммит
c47af496bd
|
@ -29,7 +29,7 @@ func NewUpdater() *Updater {
|
|||
|
||||
timestampPath := filepath.Join(os.Getenv("HOME"), ".config", "gh-update")
|
||||
return &Updater{
|
||||
Host: github.DefaultHost(),
|
||||
Host: github.DefaultGitHubHost(),
|
||||
CurrentVersion: version,
|
||||
timestampPath: timestampPath,
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ func (c *Configs) DefaultCredential() (credential *Host) {
|
|||
} else if len(c.Hosts) > 0 {
|
||||
credential = c.selectCredential()
|
||||
} else {
|
||||
credential = c.PromptFor(DefaultHost())
|
||||
credential = c.PromptFor(DefaultGitHubHost())
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -2,18 +2,19 @@ package github
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/github/hub/git"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/github/hub/git"
|
||||
)
|
||||
|
||||
var (
|
||||
GitHubHostEnv = os.Getenv("GITHUB_HOST")
|
||||
)
|
||||
|
||||
type Hosts []string
|
||||
type GitHubHosts []string
|
||||
|
||||
func (h Hosts) Include(host string) bool {
|
||||
func (h GitHubHosts) Include(host string) bool {
|
||||
for _, hh := range h {
|
||||
if hh == host {
|
||||
return true
|
||||
|
@ -23,20 +24,20 @@ func (h Hosts) Include(host string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func knownHosts() (hosts Hosts) {
|
||||
func knownGitHubHosts() (hosts GitHubHosts) {
|
||||
ghHosts, _ := git.Config("gh.host")
|
||||
for _, ghHost := range strings.Split(ghHosts, "\n") {
|
||||
hosts = append(hosts, ghHost)
|
||||
}
|
||||
|
||||
defaultHost := DefaultHost()
|
||||
defaultHost := DefaultGitHubHost()
|
||||
hosts = append(hosts, defaultHost)
|
||||
hosts = append(hosts, fmt.Sprintf("ssh.%s", defaultHost))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func DefaultHost() string {
|
||||
func DefaultGitHubHost() string {
|
||||
defaultHost := GitHubHostEnv
|
||||
if defaultHost == "" {
|
||||
defaultHost = GitHubHost
|
||||
|
|
|
@ -3,12 +3,13 @@ package github
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/github/hub/git"
|
||||
"github.com/github/hub/utils"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/github/hub/git"
|
||||
"github.com/github/hub/utils"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
|
@ -98,7 +99,7 @@ func useHttpProtocol() bool {
|
|||
}
|
||||
|
||||
func NewProjectFromURL(url *url.URL) (p *Project, err error) {
|
||||
if !knownHosts().Include(url.Host) {
|
||||
if !knownGitHubHosts().Include(url.Host) {
|
||||
err = fmt.Errorf("Invalid GitHub URL: %s", url)
|
||||
return
|
||||
}
|
||||
|
@ -131,7 +132,7 @@ func NewProject(owner, name, host string) *Project {
|
|||
}
|
||||
|
||||
if host == "" {
|
||||
host = DefaultHost()
|
||||
host = DefaultGitHubHost()
|
||||
}
|
||||
|
||||
if owner == "" {
|
||||
|
|
Загрузка…
Ссылка в новой задаче