diff options
author | 6543 <6543@obermui.de> | 2020-11-16 20:22:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 21:22:49 +0200 |
commit | 77aa742528482279012a4911a781b6b096b90fe6 (patch) | |
tree | 42eb17646d6104261a0089b65aa323f7e3eb831d /modules/migrations | |
parent | 5bd05331cef2beadc2ff87402db659ef532cb2e4 (diff) | |
download | gitea-77aa742528482279012a4911a781b6b096b90fe6.tar.gz gitea-77aa742528482279012a4911a781b6b096b90fe6.zip |
Migration: Gitlab: Support Subdirectory (#13563)
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/migrations')
-rw-r--r-- | modules/migrations/gitlab.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/migrations/gitlab.go b/modules/migrations/gitlab.go index d4b725b5be..06f4a4ba7f 100644 --- a/modules/migrations/gitlab.go +++ b/modules/migrations/gitlab.go @@ -11,6 +11,7 @@ import ( "io" "net/http" "net/url" + "path" "strings" "time" @@ -87,6 +88,23 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw return nil, err } + // split namespace and subdirectory + pathParts := strings.Split(strings.Trim(repoPath, "/"), "/") + for len(pathParts) > 2 { + if _, _, err = gitlabClient.Version.GetVersion(); err == nil { + break + } + + baseURL = path.Join(baseURL, pathParts[0]) + pathParts = pathParts[1:] + _ = gitlab.WithBaseURL(baseURL)(gitlabClient) + repoPath = strings.Join(pathParts, "/") + } + if err != nil { + log.Trace("Error could not get gitlab version: %v", err) + return nil, err + } + // Grab and store project/repo ID here, due to issues using the URL escaped path gr, _, err := gitlabClient.Projects.GetProject(repoPath, nil, nil, gitlab.WithContext(ctx)) if err != nil { |