From ed3a4cd103a687c1c9a70e1709ac838ee8543ecf Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 17 Nov 2020 08:01:33 +0100 Subject: [PATCH] Migration: Gitlab: Support Subdirectory (#13563) (#13591) Co-authored-by: techknowlogick Co-authored-by: techknowlogick --- modules/migrations/gitlab.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/migrations/gitlab.go b/modules/migrations/gitlab.go index d4b725b5b..06f4a4ba7 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 {