@@ -8,6 +8,7 @@ package migrations
88import (
99 "context"
1010 "fmt"
11+ "net/http"
1112 "net/url"
1213 "strings"
1314
2425)
2526
2627func init () {
27- RegisterDownloaderFactory (& GithubDownloaderV3Factory {})
28+ RegisterDownloaderFactory (& GitlabDownloaderFactory {})
2829}
2930
3031// GitlabDownloaderFactory defines a gitlab downloader factory
@@ -61,11 +62,13 @@ func (f *GitlabDownloaderFactory) New(opts base.MigrateOptions) (base.Downloader
6162 //oldOwner := fields[1]
6263 //oldName := strings.TrimSuffix(fields[2], ".git")
6364
64- //baseURL := u.Host
65+ baseURL := u .Scheme + "://" + u .Host
66+ repoNameSpace := strings .TrimPrefix (u .Path , "/" )
6567
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 )
6770
68- return NewGitlabDownloader (u . Host , u . Path , opts .AuthUsername , opts .AuthPassword ), nil
71+ return NewGitlabDownloader (baseURL , repoNameSpace , opts .AuthUsername , opts .AuthPassword ), nil
6972}
7073
7174// GitServiceType returns the type of git service
@@ -88,12 +91,21 @@ func NewGitlabDownloader(baseURL, repoPath, username, password string) *GitlabDo
8891 repoPath : repoPath ,
8992 }
9093
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+
97109 return & downloader
98110}
99111
@@ -105,12 +117,12 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
105117 }
106118 // convert github repo to stand Repo
107119 return & base.Repository {
108- Owner : gr .Owner .Username ,
120+ // Owner: gr.Owner.Username,
109121 Name : gr .Name ,
110122 IsPrivate : (! gr .Public ),
111123 Description : gr .Description ,
112124 OriginalURL : gr .WebURL ,
113- CloneURL : gr .HTTPURLToRepo ,
125+ CloneURL : gr .WebURL ,
114126 }, nil
115127}
116128
@@ -182,7 +194,7 @@ func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
182194 for _ , label := range ls {
183195 baseLabel := & base.Label {
184196 Name : label .Name ,
185- Color : label .Color ,
197+ Color : strings . TrimLeft ( label .Color , "#)" ) ,
186198 Description : label .Description ,
187199 }
188200 labels = append (labels , baseLabel )
@@ -246,19 +258,23 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
246258
247259// GetIssues returns issues according start and limit
248260func (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+ },
255271 }
256272
257273 var allIssues = make ([]* base.Issue , 0 , perPage )
258274
259275 issues , _ , err := g .client .Issues .ListProjectIssues (g .repoPath , opt , nil )
260276 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 )
262278 }
263279 for _ , issue := range issues {
264280
@@ -269,13 +285,18 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
269285 })
270286 }
271287
288+ var milestone string
289+ if issue .Milestone != nil {
290+ milestone = issue .Milestone .Title
291+ }
292+
272293 allIssues = append (allIssues , & base.Issue {
273294 Title : issue .Title ,
274- Number : int64 (issue .ID ),
295+ Number : int64 (issue .IID ),
275296 PosterID : int64 (issue .Author .ID ),
276297 PosterName : issue .Author .Name ,
277298 Content : issue .Description ,
278- Milestone : issue . Milestone . Title ,
299+ Milestone : milestone ,
279300 State : issue .State ,
280301 Created : * issue .CreatedAt ,
281302 Labels : labels ,
@@ -295,9 +316,9 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro
295316 PerPage : 100 ,
296317 }
297318 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 )
299320 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 )
301322 }
302323 for _ , comment := range comments {
303324 // Flatten comment threads
@@ -335,19 +356,23 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro
335356
336357// GetPullRequests returns pull requests according page and perPage
337358func (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+ },
344369 }
345370
346371 var allPRs = make ([]* base.PullRequest , 0 , perPage )
347372
348373 prs , _ , err := g .client .MergeRequests .ListProjectMergeRequests (g .repoPath , opt , nil )
349374 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 )
351376 }
352377 for _ , pr := range prs {
353378
@@ -396,13 +421,18 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
396421 }
397422 */
398423
424+ var milestone string
425+ if pr .Milestone != nil {
426+ milestone = pr .Milestone .Title
427+ }
428+
399429 allPRs = append (allPRs , & base.PullRequest {
400430 Title : pr .Title ,
401- Number : int64 (pr .ID ),
431+ Number : int64 (pr .IID ),
402432 PosterName : pr .Author .Name ,
403433 PosterID : int64 (pr .Author .ID ),
404434 Content : pr .Description ,
405- Milestone : pr . Milestone . Title ,
435+ Milestone : milestone ,
406436 State : pr .State ,
407437 Created : * pr .CreatedAt ,
408438 Closed : pr .ClosedAt ,
0 commit comments