Skip to content

Commit

Permalink
Fix issue with get repo info #130 (#132)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
codekuu and morwn authored Oct 31, 2023
1 parent 31e45b5 commit bf93ebd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/scm-clients/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions internal/scm-clients/clients/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bf93ebd

Please sign in to comment.