Skip to content

Commit

Permalink
Update util.go + test
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Lore <[email protected]>
  • Loading branch information
Johan Lore committed Nov 17, 2020
1 parent a7e3be0 commit 46d7e87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/notifier/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func parseGitAddress(s string) (string, string, error) {

path := strings.TrimLeft(u.Path, "/")
comp := strings.Split(path, "/")
if len(comp) != 2 {
return "", "", fmt.Errorf("Incorrectly formatted git address: %v", s)
}

var id strings.Builder
host := fmt.Sprintf("https://%s", u.Host)
id := comp[0] + "/" + strings.TrimSuffix(comp[1], ".git")
return host, id, nil
id.WriteString(comp[0])
for i := 1; i < len(comp); i++ {
id.WriteString("/" + strings.TrimSuffix(comp[i], ".git"))
}
return host, id.String(), nil
}

func formatNameAndDescription(event recorder.Event) (string, string) {
Expand Down
8 changes: 8 additions & 0 deletions internal/notifier/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 46d7e87

Please sign in to comment.