fix: Handle trailing slash in remote URL

This commit is contained in:
Eli Treuherz 2023-08-01 03:00:08 +00:00 committed by Jay McCure
parent 26c48951f9
commit 43f6e60bd3
2 changed files with 16 additions and 0 deletions

View File

@ -45,6 +45,7 @@ func FullNameFromURL(remoteURL string) (string, error) {
return "", errors.New("cannot parse remote: " + remoteURL)
}
repo := parts[1]
repo = strings.TrimSuffix(repo, "/")
repo = strings.TrimSuffix(repo, ".git")
return repo, nil
}

View File

@ -364,6 +364,21 @@ func TestFullNameFromURL(t *testing.T) {
want: "profclems/glab",
wantErr: nil,
},
{
remoteURL: "https://gitlab.com/profclems/glab",
want: "profclems/glab",
wantErr: nil,
},
{
remoteURL: "https://gitlab.com/profclems/glab/",
want: "profclems/glab",
wantErr: nil,
},
{
remoteURL: "https://gitlab.com/profclems/glab.git/",
want: "profclems/glab",
wantErr: nil,
},
{
remoteURL: "https://gitlab.com/owner/namespace/repo.git",
want: "owner/namespace/repo",