提交 6f65d70c 编写于 作者: D David Calavera

Remove the scheme from the project host before creating the project's git url.

When the host is absolute, like https://github.enterprise.com, the creation fail because the git url is malformed, like:

git@https://github.enterprise.com:foo/bar
上级 0c0dbcaa
......@@ -63,31 +63,38 @@ func (p *Project) GitURL(name, owner string, isSSH bool) (url string) {
owner = p.Owner
}
host := rawHost(p.Host)
if useHttpProtocol() {
url = fmt.Sprintf("https://%s/%s/%s.git", p.Host, owner, name)
url = fmt.Sprintf("https://%s/%s/%s.git", host, owner, name)
} else if isSSH {
url = fmt.Sprintf("git@%s:%s/%s.git", p.Host, owner, name)
url = fmt.Sprintf("git@%s:%s/%s.git", host, owner, name)
} else {
url = fmt.Sprintf("git://%s/%s/%s.git", p.Host, owner, name)
url = fmt.Sprintf("git://%s/%s/%s.git", host, owner, name)
}
return url
}
func useHttpProtocol() bool {
https := os.Getenv("GH_PROTOCOL")
if https == "https" {
return true
} else if https != "" {
return false
// Remove the scheme from host when the credential url is absolute.
func rawHost(host string) string {
u, err := url.Parse(host)
utils.Check(err)
if u.IsAbs() {
return u.Host
} else {
return u.Path
}
}
https, _ = git.Config("gh.protocol")
if https == "https" {
return true
func useHttpProtocol() bool {
https := os.Getenv("GH_PROTOCOL")
if https == "" {
https, _ = git.Config("gh.protocol")
}
return false
return https == "https"
}
// TODO: remove it
......
......@@ -57,7 +57,7 @@ func TestWebURL(t *testing.T) {
assert.Equal(t, "https://github.com/defunkt/hub/wiki/_pages", url)
}
func TestGitURL(t *testing.T) {
func TestGitURLGitHub(t *testing.T) {
os.Setenv("GH_PROTOCOL", "https")
project := Project{Name: "foo", Owner: "bar", Host: "github.com"}
......@@ -72,6 +72,21 @@ func TestGitURL(t *testing.T) {
assert.Equal(t, "git@github.com:jingweno/gh.git", url)
}
func TestGitURLEnterprise(t *testing.T) {
project := Project{Name: "foo", Owner: "bar", Host: "https://github.corporate.com"}
os.Setenv("GH_PROTOCOL", "https")
url := project.GitURL("gh", "jingweno", false)
assert.Equal(t, "https://github.corporate.com/jingweno/gh.git", url)
os.Setenv("GH_PROTOCOL", "git")
url = project.GitURL("gh", "jingweno", false)
assert.Equal(t, "git://github.corporate.com/jingweno/gh.git", url)
url = project.GitURL("gh", "jingweno", true)
assert.Equal(t, "git@github.corporate.com:jingweno/gh.git", url)
}
func TestParseOwnerAndName(t *testing.T) {
owner, name := parseOwnerAndName("git://github.com/jingweno/gh.git")
assert.Equal(t, "gh", name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册