Skip to content

Commit 77aa742

Browse files
6543techknowlogick
andauthored
Migration: Gitlab: Support Subdirectory (#13563)
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
1 parent 5bd0533 commit 77aa742

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

modules/migrations/gitlab.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io"
1212
"net/http"
1313
"net/url"
14+
"path"
1415
"strings"
1516
"time"
1617

@@ -87,6 +88,23 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
8788
return nil, err
8889
}
8990

91+
// split namespace and subdirectory
92+
pathParts := strings.Split(strings.Trim(repoPath, "/"), "/")
93+
for len(pathParts) > 2 {
94+
if _, _, err = gitlabClient.Version.GetVersion(); err == nil {
95+
break
96+
}
97+
98+
baseURL = path.Join(baseURL, pathParts[0])
99+
pathParts = pathParts[1:]
100+
_ = gitlab.WithBaseURL(baseURL)(gitlabClient)
101+
repoPath = strings.Join(pathParts, "/")
102+
}
103+
if err != nil {
104+
log.Trace("Error could not get gitlab version: %v", err)
105+
return nil, err
106+
}
107+
90108
// Grab and store project/repo ID here, due to issues using the URL escaped path
91109
gr, _, err := gitlabClient.Projects.GetProject(repoPath, nil, nil, gitlab.WithContext(ctx))
92110
if err != nil {

0 commit comments

Comments
 (0)