Skip to content

Commit bf93ebd

Browse files
codekuumorwn
andauthored
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 <morwnbrg@gmail.com> * Update internal/scm-clients/clients/clients_test.go Co-authored-by: Mor Weinberger <morwnbrg@gmail.com> * Update internal/scm-clients/clients/clients_test.go Co-authored-by: Mor Weinberger <morwnbrg@gmail.com> --------- Co-authored-by: Mor Weinberger <morwnbrg@gmail.com>
1 parent 31e45b5 commit bf93ebd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

internal/scm-clients/clients/clients.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func getRepoInfo(repoFullUrl string) (string, string, string, error) {
103103
return "", "", "", fmt.Errorf("missing org/repo in the repository url: %s", repoFullUrl)
104104
}
105105
repo := path[len(path)-1]
106-
namespace := strings.Split(u.Path, repo)[0]
107-
trimedNamespace := namespace[1:(len(namespace) - 1)]
106+
namespace := strings.Join(path[:len(path)-1], "/")
107+
trimedNamespace := strings.TrimLeft(namespace, "/")
108108

109109
return u.Host, trimedNamespace, repo, nil
110110
}

internal/scm-clients/clients/clients_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ func TestGetRepoInfo(t *testing.T) {
4545
RepoUrl: "https://gitlab.com/rootgroup/subgroup/secondsubgroup/test",
4646
ExpectedErr: nil,
4747
Expected: RepoInfo{BaseUrl: "gitlab.com", Namespace: "rootgroup/subgroup/secondsubgroup", Project: "test"},
48+
}, {
49+
Name: "gitlab project under sub group with same name as repo",
50+
RepoUrl: "https://gitlab.com/rootgroup/subgroup/secondsubgroup/secondsubgroup",
51+
ExpectedErr: nil,
52+
Expected: RepoInfo{BaseUrl: "gitlab.com", Namespace: "rootgroup/subgroup/secondsubgroup", Project: "secondsubgroup"},
53+
}, {
54+
Name: "gitlab project under sub org with same name as repo",
55+
RepoUrl: "https://gitlab.com/codekuu/suborg/secondsuborg/secondsuborg",
56+
ExpectedErr: nil,
57+
Expected: RepoInfo{BaseUrl: "gitlab.com", Namespace: "codekuu/suborg/secondsuborg", Project: "secondsuborg"},
4858
}}
4959

5060
for _, test := range tests {

0 commit comments

Comments
 (0)