Update util.go + test

Signed-off-by: Johan Lore <jlore@ippon.fr>
This commit is contained in:
Johan Lore 2020-11-17 09:47:19 +01:00
parent a7e3be032e
commit b5bd309b22
2 changed files with 10 additions and 7 deletions

View File

@ -32,14 +32,9 @@ func parseGitAddress(s string) (string, string, error) {
return "", "", nil
}
path := strings.TrimLeft(u.Path, "/")
comp := strings.Split(path, "/")
if len(comp) != 2 {
return "", "", fmt.Errorf("Incorrectly formatted git address: %v", s)
}
id := strings.TrimLeft(u.Path, "/")
id = strings.TrimSuffix(id, ".git")
host := fmt.Sprintf("https://%s", u.Host)
id := comp[0] + "/" + strings.TrimSuffix(comp[1], ".git")
return host, id, nil
}

View File

@ -95,3 +95,11 @@ func TestUtil_ParseGitSshWithProtocol(t *testing.T) {
require.Equal(t, "https://github.com", host)
require.Equal(t, "stefanprodan/podinfo", id)
}
func TestUtil_ParseGitHttpWithSubgroup(t *testing.T) {
addr := "https://gitlab.com/foo/bar/foo.git"
host, id, err := parseGitAddress(addr)
require.NoError(t, err)
require.Equal(t, "https://gitlab.com", host)
require.Equal(t, "foo/bar/foo", id)
}