@@ -47,7 +47,7 @@ func (f *GitlabDownloaderFactory) New(ctx context.Context, opts base.MigrateOpti
47
47
48
48
log .Trace ("Create gitlab downloader. BaseURL: %s RepoName: %s" , baseURL , repoNameSpace )
49
49
50
- return NewGitlabDownloader (ctx , baseURL , repoNameSpace , opts .AuthUsername , opts .AuthPassword , opts .AuthToken ), nil
50
+ return NewGitlabDownloader (ctx , baseURL , repoNameSpace , opts .AuthUsername , opts .AuthPassword , opts .AuthToken )
51
51
}
52
52
53
53
// GitServiceType returns the type of git service
@@ -73,7 +73,7 @@ type GitlabDownloader struct {
73
73
// NewGitlabDownloader creates a gitlab Downloader via gitlab API
74
74
// Use either a username/password, personal token entered into the username field, or anonymous/public access
75
75
// Note: Public access only allows very basic access
76
- func NewGitlabDownloader (ctx context.Context , baseURL , repoPath , username , password , token string ) * GitlabDownloader {
76
+ func NewGitlabDownloader (ctx context.Context , baseURL , repoPath , username , password , token string ) ( * GitlabDownloader , error ) {
77
77
var gitlabClient * gitlab.Client
78
78
var err error
79
79
if token != "" {
@@ -84,27 +84,27 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
84
84
85
85
if err != nil {
86
86
log .Trace ("Error logging into gitlab: %v" , err )
87
- return nil
87
+ return nil , err
88
88
}
89
89
90
90
// Grab and store project/repo ID here, due to issues using the URL escaped path
91
91
gr , _ , err := gitlabClient .Projects .GetProject (repoPath , nil , nil , gitlab .WithContext (ctx ))
92
92
if err != nil {
93
93
log .Trace ("Error retrieving project: %v" , err )
94
- return nil
94
+ return nil , err
95
95
}
96
96
97
97
if gr == nil {
98
98
log .Trace ("Error getting project, project is nil" )
99
- return nil
99
+ return nil , errors . New ( "Error getting project, project is nil" )
100
100
}
101
101
102
102
return & GitlabDownloader {
103
103
ctx : ctx ,
104
104
client : gitlabClient ,
105
105
repoID : gr .ID ,
106
106
repoName : gr .Name ,
107
- }
107
+ }, nil
108
108
}
109
109
110
110
// SetContext set context
@@ -114,10 +114,6 @@ func (g *GitlabDownloader) SetContext(ctx context.Context) {
114
114
115
115
// GetRepoInfo returns a repository information
116
116
func (g * GitlabDownloader ) GetRepoInfo () (* base.Repository , error ) {
117
- if g == nil {
118
- return nil , errors .New ("error: GitlabDownloader is nil" )
119
- }
120
-
121
117
gr , _ , err := g .client .Projects .GetProject (g .repoID , nil , nil , gitlab .WithContext (g .ctx ))
122
118
if err != nil {
123
119
return nil , err
@@ -154,10 +150,6 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
154
150
155
151
// GetTopics return gitlab topics
156
152
func (g * GitlabDownloader ) GetTopics () ([]string , error ) {
157
- if g == nil {
158
- return nil , errors .New ("error: GitlabDownloader is nil" )
159
- }
160
-
161
153
gr , _ , err := g .client .Projects .GetProject (g .repoID , nil , nil , gitlab .WithContext (g .ctx ))
162
154
if err != nil {
163
155
return nil , err
@@ -167,9 +159,6 @@ func (g *GitlabDownloader) GetTopics() ([]string, error) {
167
159
168
160
// GetMilestones returns milestones
169
161
func (g * GitlabDownloader ) GetMilestones () ([]* base.Milestone , error ) {
170
- if g == nil {
171
- return nil , errors .New ("error: GitlabDownloader is nil" )
172
- }
173
162
var perPage = 100
174
163
var state = "all"
175
164
var milestones = make ([]* base.Milestone , 0 , perPage )
@@ -228,9 +217,6 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
228
217
229
218
// GetLabels returns labels
230
219
func (g * GitlabDownloader ) GetLabels () ([]* base.Label , error ) {
231
- if g == nil {
232
- return nil , errors .New ("error: GitlabDownloader is nil" )
233
- }
234
220
var perPage = 100
235
221
var labels = make ([]* base.Label , 0 , perPage )
236
222
for i := 1 ; ; i ++ {
@@ -466,7 +452,6 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro
466
452
467
453
// GetPullRequests returns pull requests according page and perPage
468
454
func (g * GitlabDownloader ) GetPullRequests (page , perPage int ) ([]* base.PullRequest , error ) {
469
-
470
455
opt := & gitlab.ListProjectMergeRequestsOptions {
471
456
ListOptions : gitlab.ListOptions {
472
457
PerPage : perPage ,
@@ -576,7 +561,6 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
576
561
577
562
// GetReviews returns pull requests review
578
563
func (g * GitlabDownloader ) GetReviews (pullRequestNumber int64 ) ([]* base.Review , error ) {
579
-
580
564
state , _ , err := g .client .MergeRequestApprovals .GetApprovalState (g .repoID , int (pullRequestNumber ), gitlab .WithContext (g .ctx ))
581
565
if err != nil {
582
566
return nil , err
0 commit comments