@@ -35,7 +35,7 @@ type GitlabDownloaderFactory struct {
35
35
}
36
36
37
37
// New returns a Downloader related to this factory according MigrateOptions
38
- func (f * GitlabDownloaderFactory ) New (opts base.MigrateOptions ) (base.Downloader , error ) {
38
+ func (f * GitlabDownloaderFactory ) New (ctx context. Context , opts base.MigrateOptions ) (base.Downloader , error ) {
39
39
u , err := url .Parse (opts .CloneAddr )
40
40
if err != nil {
41
41
return nil , err
@@ -47,7 +47,7 @@ func (f *GitlabDownloaderFactory) New(opts base.MigrateOptions) (base.Downloader
47
47
48
48
log .Trace ("Create gitlab downloader. BaseURL: %s RepoName: %s" , baseURL , repoNameSpace )
49
49
50
- return NewGitlabDownloader (baseURL , repoNameSpace , opts .AuthUsername , opts .AuthPassword , opts .AuthToken ), nil
50
+ return NewGitlabDownloader (ctx , baseURL , repoNameSpace , opts .AuthUsername , opts .AuthPassword , opts .AuthToken ), nil
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 (baseURL , repoPath , username , password , token string ) * GitlabDownloader {
76
+ func NewGitlabDownloader (ctx context. Context , baseURL , repoPath , username , password , token string ) * GitlabDownloader {
77
77
var gitlabClient * gitlab.Client
78
78
var err error
79
79
if token != "" {
@@ -88,7 +88,7 @@ func NewGitlabDownloader(baseURL, repoPath, username, password, token string) *G
88
88
}
89
89
90
90
// Grab and store project/repo ID here, due to issues using the URL escaped path
91
- gr , _ , err := gitlabClient .Projects .GetProject (repoPath , nil , nil )
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
94
return nil
@@ -100,7 +100,7 @@ func NewGitlabDownloader(baseURL, repoPath, username, password, token string) *G
100
100
}
101
101
102
102
return & GitlabDownloader {
103
- ctx : context . Background () ,
103
+ ctx : ctx ,
104
104
client : gitlabClient ,
105
105
repoID : gr .ID ,
106
106
repoName : gr .Name ,
@@ -118,7 +118,7 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
118
118
return nil , errors .New ("error: GitlabDownloader is nil" )
119
119
}
120
120
121
- gr , _ , err := g .client .Projects .GetProject (g .repoID , nil , nil )
121
+ gr , _ , err := g .client .Projects .GetProject (g .repoID , nil , nil , gitlab . WithContext ( g . ctx ) )
122
122
if err != nil {
123
123
return nil , err
124
124
}
@@ -158,7 +158,7 @@ func (g *GitlabDownloader) GetTopics() ([]string, error) {
158
158
return nil , errors .New ("error: GitlabDownloader is nil" )
159
159
}
160
160
161
- gr , _ , err := g .client .Projects .GetProject (g .repoID , nil , nil )
161
+ gr , _ , err := g .client .Projects .GetProject (g .repoID , nil , nil , gitlab . WithContext ( g . ctx ) )
162
162
if err != nil {
163
163
return nil , err
164
164
}
@@ -179,7 +179,7 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
179
179
ListOptions : gitlab.ListOptions {
180
180
Page : i ,
181
181
PerPage : perPage ,
182
- }}, nil )
182
+ }}, nil , gitlab . WithContext ( g . ctx ) )
183
183
if err != nil {
184
184
return nil , err
185
185
}
@@ -237,7 +237,7 @@ func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
237
237
ls , _ , err := g .client .Labels .ListLabels (g .repoID , & gitlab.ListLabelsOptions {
238
238
Page : i ,
239
239
PerPage : perPage ,
240
- }, nil )
240
+ }, nil , gitlab . WithContext ( g . ctx ) )
241
241
if err != nil {
242
242
return nil , err
243
243
}
@@ -288,7 +288,7 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
288
288
ls , _ , err := g .client .Releases .ListReleases (g .repoID , & gitlab.ListReleasesOptions {
289
289
Page : i ,
290
290
PerPage : perPage ,
291
- }, nil )
291
+ }, nil , gitlab . WithContext ( g . ctx ) )
292
292
if err != nil {
293
293
return nil , err
294
294
}
@@ -305,11 +305,18 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
305
305
306
306
// GetAsset returns an asset
307
307
func (g * GitlabDownloader ) GetAsset (tag string , id int64 ) (io.ReadCloser , error ) {
308
- link , _ , err := g .client .ReleaseLinks .GetReleaseLink (g .repoID , tag , int (id ))
308
+ link , _ , err := g .client .ReleaseLinks .GetReleaseLink (g .repoID , tag , int (id ), gitlab . WithContext ( g . ctx ) )
309
309
if err != nil {
310
310
return nil , err
311
311
}
312
- resp , err := http .Get (link .URL )
312
+
313
+ req , err := http .NewRequest ("GET" , link .URL , nil )
314
+ if err != nil {
315
+ return nil , err
316
+ }
317
+ req = req .WithContext (g .ctx )
318
+
319
+ resp , err := http .DefaultClient .Do (req )
313
320
if err != nil {
314
321
return nil , err
315
322
}
@@ -336,7 +343,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
336
343
337
344
var allIssues = make ([]* base.Issue , 0 , perPage )
338
345
339
- issues , _ , err := g .client .Issues .ListProjectIssues (g .repoID , opt , nil )
346
+ issues , _ , err := g .client .Issues .ListProjectIssues (g .repoID , opt , nil , gitlab . WithContext ( g . ctx ) )
340
347
if err != nil {
341
348
return nil , false , fmt .Errorf ("error while listing issues: %v" , err )
342
349
}
@@ -393,14 +400,14 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro
393
400
comments , resp , err = g .client .Discussions .ListIssueDiscussions (g .repoID , int (realIssueNumber ), & gitlab.ListIssueDiscussionsOptions {
394
401
Page : page ,
395
402
PerPage : 100 ,
396
- }, nil )
403
+ }, nil , gitlab . WithContext ( g . ctx ) )
397
404
} else {
398
405
// If this is a PR, we need to figure out the Gitlab/original PR ID to be passed below
399
406
realIssueNumber = issueNumber - g .issueCount
400
407
comments , resp , err = g .client .Discussions .ListMergeRequestDiscussions (g .repoID , int (realIssueNumber ), & gitlab.ListMergeRequestDiscussionsOptions {
401
408
Page : page ,
402
409
PerPage : 100 ,
403
- }, nil )
410
+ }, nil , gitlab . WithContext ( g . ctx ) )
404
411
}
405
412
406
413
if err != nil {
@@ -455,7 +462,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
455
462
456
463
var allPRs = make ([]* base.PullRequest , 0 , perPage )
457
464
458
- prs , _ , err := g .client .MergeRequests .ListProjectMergeRequests (g .repoID , opt , nil )
465
+ prs , _ , err := g .client .MergeRequests .ListProjectMergeRequests (g .repoID , opt , nil , gitlab . WithContext ( g . ctx ) )
459
466
if err != nil {
460
467
return nil , fmt .Errorf ("error while listing merge requests: %v" , err )
461
468
}
@@ -536,7 +543,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
536
543
// GetReviews returns pull requests review
537
544
func (g * GitlabDownloader ) GetReviews (pullRequestNumber int64 ) ([]* base.Review , error ) {
538
545
539
- state , _ , err := g .client .MergeRequestApprovals .GetApprovalState (g .repoID , int (pullRequestNumber ))
546
+ state , _ , err := g .client .MergeRequestApprovals .GetApprovalState (g .repoID , int (pullRequestNumber ), gitlab . WithContext ( g . ctx ) )
540
547
if err != nil {
541
548
return nil , err
542
549
}
0 commit comments