@ -35,7 +35,7 @@ type GitlabDownloaderFactory struct {
}
}
// New returns a Downloader related to this factory according MigrateOptions
// New returns a Downloader related to this factory according MigrateOptions
func ( f * GitlabDownloaderFactory ) New ( opts base . MigrateOptions ) ( base . Downloader , error ) {
func ( f * GitlabDownloaderFactory ) New ( ctx context . Context , opts base . MigrateOptions ) ( base . Downloader , error ) {
u , err := url . Parse ( opts . CloneAddr )
u , err := url . Parse ( opts . CloneAddr )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -47,7 +47,7 @@ func (f *GitlabDownloaderFactory) New(opts base.MigrateOptions) (base.Downloader
log . Trace ( "Create gitlab downloader. BaseURL: %s RepoName: %s" , baseURL , repoNameSpace )
log . Trace ( "Create gitlab downloader. BaseURL: %s RepoName: %s" , baseURL , repoNameSpace )
return NewGitlabDownloader ( baseURL , repoNameSpace , opts . AuthUsername , opts . AuthPassword , opts . AuthToken ) , nil
return NewGitlabDownloader ( ctx , baseURL , repoNameSpace , opts . AuthUsername , opts . AuthPassword , opts . AuthToken ) , nil
}
}
// GitServiceType returns the type of git service
// GitServiceType returns the type of git service
@ -73,7 +73,7 @@ type GitlabDownloader struct {
// NewGitlabDownloader creates a gitlab Downloader via gitlab API
// NewGitlabDownloader creates a gitlab Downloader via gitlab API
// Use either a username/password, personal token entered into the username field, or anonymous/public access
// Use either a username/password, personal token entered into the username field, or anonymous/public access
// Note: Public access only allows very basic access
// Note: Public access only allows very basic access
func NewGitlabDownloader ( baseURL , repoPath , username , password , token string ) * GitlabDownloader {
func NewGitlabDownloader ( ctx context . Context , baseURL , repoPath , username , password , token string ) * GitlabDownloader {
var gitlabClient * gitlab . Client
var gitlabClient * gitlab . Client
var err error
var err error
if token != "" {
if token != "" {
@ -88,7 +88,7 @@ func NewGitlabDownloader(baseURL, repoPath, username, password, token string) *G
}
}
// Grab and store project/repo ID here, due to issues using the URL escaped path
// Grab and store project/repo ID here, due to issues using the URL escaped path
gr , _ , err := gitlabClient . Projects . GetProject ( repoPath , nil , nil )
gr , _ , err := gitlabClient . Projects . GetProject ( repoPath , nil , nil , gitlab . WithContext ( ctx ) )
if err != nil {
if err != nil {
log . Trace ( "Error retrieving project: %v" , err )
log . Trace ( "Error retrieving project: %v" , err )
return nil
return nil
@ -100,7 +100,7 @@ func NewGitlabDownloader(baseURL, repoPath, username, password, token string) *G
}
}
return & GitlabDownloader {
return & GitlabDownloader {
ctx : con te xt . Background ( ) ,
ctx : ctx ,
client : gitlabClient ,
client : gitlabClient ,
repoID : gr . ID ,
repoID : gr . ID ,
repoName : gr . Name ,
repoName : gr . Name ,
@ -118,7 +118,7 @@ func (g *GitlabDownloader) GetRepoInfo() (*base.Repository, error) {
return nil , errors . New ( "error: GitlabDownloader is nil" )
return nil , errors . New ( "error: GitlabDownloader is nil" )
}
}
gr , _ , err := g . client . Projects . GetProject ( g . repoID , nil , nil )
gr , _ , err := g . client . Projects . GetProject ( g . repoID , nil , nil , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -158,7 +158,7 @@ func (g *GitlabDownloader) GetTopics() ([]string, error) {
return nil , errors . New ( "error: GitlabDownloader is nil" )
return nil , errors . New ( "error: GitlabDownloader is nil" )
}
}
gr , _ , err := g . client . Projects . GetProject ( g . repoID , nil , nil )
gr , _ , err := g . client . Projects . GetProject ( g . repoID , nil , nil , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -179,7 +179,7 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
ListOptions : gitlab . ListOptions {
ListOptions : gitlab . ListOptions {
Page : i ,
Page : i ,
PerPage : perPage ,
PerPage : perPage ,
} } , nil )
} } , nil , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -237,7 +237,7 @@ func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
ls , _ , err := g . client . Labels . ListLabels ( g . repoID , & gitlab . ListLabelsOptions {
ls , _ , err := g . client . Labels . ListLabels ( g . repoID , & gitlab . ListLabelsOptions {
Page : i ,
Page : i ,
PerPage : perPage ,
PerPage : perPage ,
} , nil )
} , nil , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -288,7 +288,7 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
ls , _ , err := g . client . Releases . ListReleases ( g . repoID , & gitlab . ListReleasesOptions {
ls , _ , err := g . client . Releases . ListReleases ( g . repoID , & gitlab . ListReleasesOptions {
Page : i ,
Page : i ,
PerPage : perPage ,
PerPage : perPage ,
} , nil )
} , nil , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -305,11 +305,18 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
// GetAsset returns an asset
// GetAsset returns an asset
func ( g * GitlabDownloader ) GetAsset ( tag string , id int64 ) ( io . ReadCloser , error ) {
func ( g * GitlabDownloader ) GetAsset ( tag string , id int64 ) ( io . ReadCloser , error ) {
link , _ , err := g . client . ReleaseLinks . GetReleaseLink ( g . repoID , tag , int ( id ) )
link , _ , err := g . client . ReleaseLinks . GetReleaseLink ( g . repoID , tag , int ( id ) , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
resp , err := http . Get ( link . URL )
req , err := http . NewRequest ( "GET" , link . URL , nil )
if err != nil {
return nil , err
}
req = req . WithContext ( g . ctx )
resp , err := http . DefaultClient . Do ( req )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -336,7 +343,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
var allIssues = make ( [ ] * base . Issue , 0 , perPage )
var allIssues = make ( [ ] * base . Issue , 0 , perPage )
issues , _ , err := g . client . Issues . ListProjectIssues ( g . repoID , opt , nil )
issues , _ , err := g . client . Issues . ListProjectIssues ( g . repoID , opt , nil , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , false , fmt . Errorf ( "error while listing issues: %v" , err )
return nil , false , fmt . Errorf ( "error while listing issues: %v" , err )
}
}
@ -393,14 +400,14 @@ func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, erro
comments , resp , err = g . client . Discussions . ListIssueDiscussions ( g . repoID , int ( realIssueNumber ) , & gitlab . ListIssueDiscussionsOptions {
comments , resp , err = g . client . Discussions . ListIssueDiscussions ( g . repoID , int ( realIssueNumber ) , & gitlab . ListIssueDiscussionsOptions {
Page : page ,
Page : page ,
PerPage : 100 ,
PerPage : 100 ,
} , nil )
} , nil , gitlab . WithContext ( g . ctx ) )
} else {
} else {
// If this is a PR, we need to figure out the Gitlab/original PR ID to be passed below
// If this is a PR, we need to figure out the Gitlab/original PR ID to be passed below
realIssueNumber = issueNumber - g . issueCount
realIssueNumber = issueNumber - g . issueCount
comments , resp , err = g . client . Discussions . ListMergeRequestDiscussions ( g . repoID , int ( realIssueNumber ) , & gitlab . ListMergeRequestDiscussionsOptions {
comments , resp , err = g . client . Discussions . ListMergeRequestDiscussions ( g . repoID , int ( realIssueNumber ) , & gitlab . ListMergeRequestDiscussionsOptions {
Page : page ,
Page : page ,
PerPage : 100 ,
PerPage : 100 ,
} , nil )
} , nil , gitlab . WithContext ( g . ctx ) )
}
}
if err != nil {
if err != nil {
@ -455,7 +462,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
var allPRs = make ( [ ] * base . PullRequest , 0 , perPage )
var allPRs = make ( [ ] * base . PullRequest , 0 , perPage )
prs , _ , err := g . client . MergeRequests . ListProjectMergeRequests ( g . repoID , opt , nil )
prs , _ , err := g . client . MergeRequests . ListProjectMergeRequests ( g . repoID , opt , nil , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , fmt . Errorf ( "error while listing merge requests: %v" , err )
return nil , fmt . Errorf ( "error while listing merge requests: %v" , err )
}
}
@ -536,7 +543,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
// GetReviews returns pull requests review
// GetReviews returns pull requests review
func ( g * GitlabDownloader ) GetReviews ( pullRequestNumber int64 ) ( [ ] * base . Review , error ) {
func ( g * GitlabDownloader ) GetReviews ( pullRequestNumber int64 ) ( [ ] * base . Review , error ) {
state , _ , err := g . client . MergeRequestApprovals . GetApprovalState ( g . repoID , int ( pullRequestNumber ) )
state , _ , err := g . client . MergeRequestApprovals . GetApprovalState ( g . repoID , int ( pullRequestNumber ) , gitlab . WithContext ( g . ctx ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}