@@ -90,12 +90,17 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
90
90
91
91
// split namespace and subdirectory
92
92
pathParts := strings .Split (strings .Trim (repoPath , "/" ), "/" )
93
- for len (pathParts ) > 2 {
94
- if _ , _ , err = gitlabClient .Version .GetVersion (); err == nil {
93
+ var resp * gitlab.Response
94
+ u , _ := url .Parse (baseURL )
95
+ for len (pathParts ) >= 2 {
96
+ _ , resp , err = gitlabClient .Version .GetVersion ()
97
+ if err == nil || resp != nil && resp .StatusCode == 401 {
98
+ err = nil // if no authentication given, this still should work
95
99
break
96
100
}
97
101
98
- baseURL = path .Join (baseURL , pathParts [0 ])
102
+ u .Path = path .Join (u .Path , pathParts [0 ])
103
+ baseURL = u .String ()
99
104
pathParts = pathParts [1 :]
100
105
_ = gitlab .WithBaseURL (baseURL )(gitlabClient )
101
106
repoPath = strings .Join (pathParts , "/" )
@@ -105,6 +110,8 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
105
110
return nil , err
106
111
}
107
112
113
+ log .Trace ("gitlab downloader: use BaseURL: '%s' and RepoPath: '%s'" , baseURL , repoPath )
114
+
108
115
// Grab and store project/repo ID here, due to issues using the URL escaped path
109
116
gr , _ , err := gitlabClient .Projects .GetProject (repoPath , nil , nil , gitlab .WithContext (ctx ))
110
117
if err != nil {
@@ -602,8 +609,12 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
602
609
603
610
// GetReviews returns pull requests review
604
611
func (g * GitlabDownloader ) GetReviews (pullRequestNumber int64 ) ([]* base.Review , error ) {
605
- state , _ , err := g .client .MergeRequestApprovals .GetApprovalState (g .repoID , int (pullRequestNumber ), gitlab .WithContext (g .ctx ))
612
+ state , resp , err := g .client .MergeRequestApprovals .GetApprovalState (g .repoID , int (pullRequestNumber ), gitlab .WithContext (g .ctx ))
606
613
if err != nil {
614
+ if resp != nil && resp .StatusCode == 404 {
615
+ log .Error (fmt .Sprintf ("GitlabDownloader: while migrating a error occurred: '%s'" , err .Error ()))
616
+ return []* base.Review {}, nil
617
+ }
607
618
return nil , err
608
619
}
609
620
0 commit comments