fluxcd / go-git-providers

Git provider client for Go
https://fluxcd.io
Apache License 2.0
71 stars 33 forks source link

GitLab GetCloneURL returns the wrong clone url in certain conditions #267

Open janderssonse opened 3 months ago

janderssonse commented 3 months ago

Describe the bug

GitLab GetCloneUrl returns the wrong clone url in certain conditions.

To Reproduce

Here is a public project where you can reproduce it: https://gitlab.com/hanklank/anki-lpic

Use the list to get the public repositories for this user: https://gitlab.com/hanklank Get the clone url for the project anki-lpic. Notice it should end with: anki-lpic but ends with lpic (bug).

Had quick look in the code, The error is likely due to that go-git-providers only use the project name when creating the repository struct, and does not care about the real clone url - these will differ at times, like in the case given-> project NAME is lpic, but CLONE URL (and project path) is anki-lpic. I think if go-gitprovider would replace using Name with Path from the gitlab api it would fix it for all cases. Example: https://gitlab.com/api/v4/projects/hanklank%2Fanki-lpic name differs from clone url.

Currently this leads to GetCloneURL always giving the wrong clone url in these cases.

https://github.com/fluxcd/go-git-providers/blob/df839c56a32353a502ef9f9f3ff3209699de3fd3/gitlab/client_repositories_user.go#L83

(same with org-repos so it would need to be fixed there too)

Expected behavior

GitLab's GetCloneUrl should end in the real clone url, ie anki-lpic not in project name lpic.

Additional context