@@ -23,25 +23,29 @@ func (d *GitLabDetector) Detect(src, _ string) (string, bool, error) {
2323}
2424
2525func (d * GitLabDetector ) detectHTTP (src string ) (string , bool , error ) {
26- parts := strings .Split (src , "/" )
27- if len (parts ) < 3 {
28- return "" , false , fmt .Errorf (
29- "GitLab URLs should be gitlab.com/username/repo" )
30- }
31-
32- urlStr := fmt .Sprintf ("https://%s" , strings .Join (parts [:3 ], "/" ))
33- repoUrl , err := url .Parse (urlStr )
26+ repoUrl , err := url .Parse (fmt .Sprintf ("https://%s" , src ))
3427 if err != nil {
3528 return "" , true , fmt .Errorf ("error parsing GitLab URL: %s" , err )
3629 }
3730
38- if ! strings .HasSuffix (repoUrl .Path , ".git" ) {
39- repoUrl .Path += ".git"
31+ parts := strings .Split (repoUrl .Path , "//" )
32+
33+ if len (strings .Split (parts [0 ], "/" )) < 3 {
34+ return "" , false , fmt .Errorf (
35+ "GitLab URLs should be gitlab.com/username/repo " +
36+ "or gitlab.com/organization/project/repo" )
4037 }
4138
42- if len (parts ) > 3 {
43- repoUrl .Path += "//" + strings .Join (parts [3 :], "/" )
39+ if len (parts ) > 2 {
40+ return "" , false , fmt .Errorf (
41+ "URL malformed: \" //\" can only used once in path" )
42+ }
43+
44+ if ! strings .HasSuffix (parts [0 ], ".git" ) {
45+ parts [0 ] += ".git"
4446 }
4547
48+ repoUrl .Path = fmt .Sprintf ("%s" , strings .Join (parts , "//" ))
49+
4650 return "git::" + repoUrl .String (), true , nil
4751}
0 commit comments