Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyguava committed Sep 26, 2022
1 parent a6ca6a0 commit 1841f0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions api/internal/git/repospec.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ func peelQuery(arg string) (string, string, time.Duration, bool) {
return parsed.Path, ref, duration, submodules
}

var userRegex = regexp.MustCompile(`[a-zA-Z][a-zA-Z0-9-]*@`)

func parseHostSpec(n string) (string, string, error) {
var host string
consumeHostStrings := func(parts []string) {
Expand Down Expand Up @@ -274,16 +272,18 @@ func parseHostSpec(n string) (string, string, error) {
return host, n, err
}

var userRegex = regexp.MustCompile(`^(?:ssh://|git::)?([a-zA-Z][a-zA-Z0-9-]*@)`)

func normalizeGitHostSpec(host string) (string, error) {
s := strings.ToLower(host)
m := userRegex.FindString(host)
m := userRegex.FindStringSubmatch(host)
if strings.Contains(s, "github.com") {
switch {
case m != "":
if strings.HasPrefix(s, "git::") && m != "git" {
case len(m) > 0:
if strings.HasPrefix(s, "git::") && m[1] != "git@" {
return "", fmt.Errorf("git protocol on github.com only allows git@ user")
}
host = m + "github.com:"
host = m[1] + "github.com:"
case strings.Contains(s, "ssh:"):
host = "[email protected]:"
default:
Expand Down
4 changes: 2 additions & 2 deletions api/internal/git/repospec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) {
{
name: "t25",
input: "https://[email protected]/kubernetes-sigs/kustomize",
cloneSpec: "org-12345@github.com:kubernetes-sigs/kustomize.git",
cloneSpec: "https://github.com/kubernetes-sigs/kustomize.git",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "org-12345@github.com:",
Host: "https://github.com/",
OrgRepo: "kubernetes-sigs/kustomize",
GitSuffix: ".git",
},
Expand Down

0 comments on commit 1841f0b

Please sign in to comment.