]> source.dussan.org Git - gitea.git/commitdiff
Migration: Gitlab: Support Subdirectory (#13563)
author6543 <6543@obermui.de>
Mon, 16 Nov 2020 19:22:49 +0000 (20:22 +0100)
committerGitHub <noreply@github.com>
Mon, 16 Nov 2020 19:22:49 +0000 (21:22 +0200)
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
modules/migrations/gitlab.go

index d4b725b5beaa0cc5d3278541e4fa4af012b54a7d..06f4a4ba7fe9ecd70c5fc7befa75f422926b9a7b 100644 (file)
@@ -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 {