From b5bd309b22f6b121749b681d600204a139de0b1a Mon Sep 17 00:00:00 2001 From: Johan Lore Date: Tue, 17 Nov 2020 09:47:19 +0100 Subject: [PATCH] Update util.go + test Signed-off-by: Johan Lore --- internal/notifier/util.go | 9 ++------- internal/notifier/util_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/notifier/util.go b/internal/notifier/util.go index f31e8ec..c6c60dc 100644 --- a/internal/notifier/util.go +++ b/internal/notifier/util.go @@ -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 } diff --git a/internal/notifier/util_test.go b/internal/notifier/util_test.go index fb426dc..d65be75 100644 --- a/internal/notifier/util_test.go +++ b/internal/notifier/util_test.go @@ -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) +}