From bf93ebd995d3027737608e92b42007d29ac9f6d0 Mon Sep 17 00:00:00 2001 From: Kevin Kuusela <47852530+codekuu@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:52:51 +0100 Subject: [PATCH] Fix issue with get repo info #130 (#132) * Fixed issue related to #130 * Adding test coverage * Fixed test for clients Changed BaseURL in test from gitlab to github. * Update internal/scm-clients/clients/clients_test.go Co-authored-by: Mor Weinberger * Update internal/scm-clients/clients/clients_test.go Co-authored-by: Mor Weinberger * Update internal/scm-clients/clients/clients_test.go Co-authored-by: Mor Weinberger --------- Co-authored-by: Mor Weinberger --- internal/scm-clients/clients/clients.go | 4 ++-- internal/scm-clients/clients/clients_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/scm-clients/clients/clients.go b/internal/scm-clients/clients/clients.go index 3678e08..aed7e6f 100644 --- a/internal/scm-clients/clients/clients.go +++ b/internal/scm-clients/clients/clients.go @@ -103,8 +103,8 @@ func getRepoInfo(repoFullUrl string) (string, string, string, error) { return "", "", "", fmt.Errorf("missing org/repo in the repository url: %s", repoFullUrl) } repo := path[len(path)-1] - namespace := strings.Split(u.Path, repo)[0] - trimedNamespace := namespace[1:(len(namespace) - 1)] + namespace := strings.Join(path[:len(path)-1], "/") + trimedNamespace := strings.TrimLeft(namespace, "/") return u.Host, trimedNamespace, repo, nil } diff --git a/internal/scm-clients/clients/clients_test.go b/internal/scm-clients/clients/clients_test.go index 57dff65..dee7f90 100644 --- a/internal/scm-clients/clients/clients_test.go +++ b/internal/scm-clients/clients/clients_test.go @@ -45,6 +45,16 @@ func TestGetRepoInfo(t *testing.T) { RepoUrl: "https://gitlab.com/rootgroup/subgroup/secondsubgroup/test", ExpectedErr: nil, Expected: RepoInfo{BaseUrl: "gitlab.com", Namespace: "rootgroup/subgroup/secondsubgroup", Project: "test"}, + }, { + Name: "gitlab project under sub group with same name as repo", + RepoUrl: "https://gitlab.com/rootgroup/subgroup/secondsubgroup/secondsubgroup", + ExpectedErr: nil, + Expected: RepoInfo{BaseUrl: "gitlab.com", Namespace: "rootgroup/subgroup/secondsubgroup", Project: "secondsubgroup"}, + }, { + Name: "gitlab project under sub org with same name as repo", + RepoUrl: "https://gitlab.com/codekuu/suborg/secondsuborg/secondsuborg", + ExpectedErr: nil, + Expected: RepoInfo{BaseUrl: "gitlab.com", Namespace: "codekuu/suborg/secondsuborg", Project: "secondsuborg"}, }} for _, test := range tests {