@@ -8,6 +8,7 @@ package migrations
8
8
import (
9
9
"context"
10
10
"fmt"
11
+ "net/http"
11
12
"net/url"
12
13
"strings"
13
14
24
25
)
25
26
26
27
func init () {
27
- RegisterDownloaderFactory (& GithubDownloaderV3Factory {})
28
+ RegisterDownloaderFactory (& GitlabDownloaderFactory {})
28
29
}
29
30
30
31
// GitlabDownloaderFactory defines a gitlab downloader factory
@@ -61,11 +62,13 @@ func (f *GitlabDownloaderFactory) New(opts base.MigrateOptions) (base.Downloader
61
62
//oldOwner := fields[1]
62
63
//oldName := strings.TrimSuffix(fields[2], ".git")
63
64
64
- //baseURL := u.Host
65
+ baseURL := u .Scheme + "://" + u .Host
66
+ repoNameSpace := strings .TrimPrefix (u .Path , "/" )
65
67
66
- log .Trace ("Create gitlab downloader: %s/%s" , opts .AuthUsername , opts .RepoName )
68
+ log .Trace ("Create gitlab downloader. baseURL: %s Token: %s RepoName: %s" , baseURL , opts .AuthUsername , repoNameSpace )
69
+ log .Trace ("opts.CloneAddr %v" , opts .CloneAddr )
67
70
68
- return NewGitlabDownloader (u . Host , u . Path , opts .AuthUsername , opts .AuthPassword ), nil
71
+ return NewGitlabDownloader (baseURL , repoNameSpace , opts .AuthUsername , opts .AuthPassword ), nil
69
72
}
70
73
71
74
// GitServiceType returns the type of git service
@@ -88,12 +91,21 @@ func NewGitlabDownloader(baseURL, repoPath, username, password string) *GitlabDo
88
91
repoPath : repoPath ,
89
92
}
90
93
91
- var err error
92
- downloader .client , err = gitlab .NewBasicAuthClient (nil , baseURL , username , password )
93
- if err != nil {
94
- log .Warn ("Error creating Gitlab Client:" , err )
95
- return nil
96
- }
94
+ var client * http.Client
95
+
96
+ gitlabClient := gitlab .NewClient (client , username )
97
+ gitlabClient .SetBaseURL (baseURL )
98
+
99
+ /*
100
+ gitlabClient, err := gitlab.NewBasicAuthClient(nil, baseURL, username, password)
101
+ if err != nil {
102
+ log.Trace("Error logging into gitlab: %v", err)
103
+ return nil
104
+ }
105
+ */
106
+
107
+ downloader .client = gitlabClient
108
+
97
109
return & downloader
98
110
}
99
111
@@ -105,12 +117,12 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
105
117
}
106
118
// convert github repo to stand Repo
107
119
return & base.Repository {
108
- Owner : gr .Owner .Username ,
120
+ // Owner: gr.Owner.Username,
109
121
Name : gr .Name ,
110
122
IsPrivate : (! gr .Public ),
111
123
Description : gr .Description ,
112
124
OriginalURL : gr .WebURL ,
113
- CloneURL : gr .HTTPURLToRepo ,
125
+ CloneURL : gr .WebURL ,
114
126
}, nil
115
127
}
116
128
@@ -182,7 +194,7 @@ func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
182
194
for _ , label := range ls {
183
195
baseLabel := & base.Label {
184
196
Name : label .Name ,
185
- Color : label .Color ,
197
+ Color : strings . TrimLeft ( label .Color , "#)" ) ,
186
198
Description : label .Description ,
187
199
}
188
200
labels = append (labels , baseLabel )
@@ -246,19 +258,23 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
246
258
247
259
// GetIssues returns issues according start and limit
248
260
func (g * GitlabDownloader ) GetIssues (page , perPage int ) ([]* base.Issue , bool , error ) {
249
- opt := & gitlab.ListProjectIssuesOptions {}
250
- * opt .State = "all"
251
- * opt .Sort = "created"
252
- opt .ListOptions = gitlab.ListOptions {
253
- PerPage : perPage ,
254
- Page : page ,
261
+ state := "all"
262
+ sort := "asc"
263
+
264
+ opt := & gitlab.ListProjectIssuesOptions {
265
+ State : & state ,
266
+ Sort : & sort ,
267
+ ListOptions : gitlab.ListOptions {
268
+ PerPage : perPage ,
269
+ Page : page ,
270
+ },
255
271
}
256
272
257
273
var allIssues = make ([]* base.Issue , 0 , perPage )
258
274
259
275
issues , _ , err := g .client .Issues .ListProjectIssues (g .repoPath , opt , nil )
260
276
if err != nil {
261
- return nil , false , fmt .Errorf ("error while listing repos : %v" , err )
277
+ return nil , false , fmt .Errorf ("error while listing issues : %v" , err )
262
278
}
263
279
for _ , issue := range issues {
264
280
@@ -269,13 +285,18 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
269
285
})
270
286
}
271
287
288
+ var milestone string
289
+ if issue .Milestone != nil {
290
+ milestone = issue .Milestone .Title
291
+ }
292
+
272
293
allIssues = append (allIssues , & base.Issue {
273
294
Title : issue .Title ,
274
- Number : int64 (issue .ID ),
295
+ Number : int64 (issue .IID ),
275
296
PosterID : int64 (issue .Author .ID ),
276
297
PosterName : issue .Author .Name ,
277
298
Content : issue .Description ,
278
- Milestone : issue . Milestone . Title ,
299
+ Milestone : milestone ,
279
300
State : issue .State ,
280
301
Created : * issue .CreatedAt ,
281
302
Labels : labels ,
@@ -295,9 +316,9 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro
295
316
PerPage : 100 ,
296
317
}
297
318
for {
298
- comments , resp , err := g .client .Discussions .ListIssueDiscussions (g .repoPath , int (issueNumber ), opt , nil )
319
+ comments , resp , err := g .client .Discussions .ListIssueDiscussions (url . PathEscape ( g .repoPath ) , int (issueNumber ), opt , nil )
299
320
if err != nil {
300
- return nil , fmt .Errorf ("error while listing repos : %v" , err )
321
+ return nil , fmt .Errorf ("error while listing comments : %v %v" , g . repoPath , err )
301
322
}
302
323
for _ , comment := range comments {
303
324
// Flatten comment threads
@@ -335,19 +356,23 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro
335
356
336
357
// GetPullRequests returns pull requests according page and perPage
337
358
func (g * GitlabDownloader ) GetPullRequests (page , perPage int ) ([]* base.PullRequest , error ) {
338
- opt := & gitlab.ListProjectMergeRequestsOptions {}
339
- * opt .State = "all"
340
- * opt .Sort = "created"
341
- opt .ListOptions = gitlab.ListOptions {
342
- PerPage : perPage ,
343
- Page : page ,
359
+ //state := "all"
360
+ //sort := "created"
361
+
362
+ opt := & gitlab.ListProjectMergeRequestsOptions {
363
+ //State: &state,
364
+ //Sort: &sort,
365
+ ListOptions : gitlab.ListOptions {
366
+ PerPage : perPage ,
367
+ Page : page ,
368
+ },
344
369
}
345
370
346
371
var allPRs = make ([]* base.PullRequest , 0 , perPage )
347
372
348
373
prs , _ , err := g .client .MergeRequests .ListProjectMergeRequests (g .repoPath , opt , nil )
349
374
if err != nil {
350
- return nil , fmt .Errorf ("error while listing repos : %v" , err )
375
+ return nil , fmt .Errorf ("error while listing merge requests : %v" , err )
351
376
}
352
377
for _ , pr := range prs {
353
378
@@ -396,13 +421,18 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
396
421
}
397
422
*/
398
423
424
+ var milestone string
425
+ if pr .Milestone != nil {
426
+ milestone = pr .Milestone .Title
427
+ }
428
+
399
429
allPRs = append (allPRs , & base.PullRequest {
400
430
Title : pr .Title ,
401
- Number : int64 (pr .ID ),
431
+ Number : int64 (pr .IID ),
402
432
PosterName : pr .Author .Name ,
403
433
PosterID : int64 (pr .Author .ID ),
404
434
Content : pr .Description ,
405
- Milestone : pr . Milestone . Title ,
435
+ Milestone : milestone ,
406
436
State : pr .State ,
407
437
Created : * pr .CreatedAt ,
408
438
Closed : pr .ClosedAt ,
0 commit comments