@@ -90,28 +90,37 @@ func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, tok
9090 maxPerPage : 100 ,
9191 }
9292
93- client := & http.Client {
94- Transport : & http.Transport {
95- Proxy : func (req * http.Request ) (* url.URL , error ) {
96- req .SetBasicAuth (userName , password )
97- return proxy .Proxy ()(req )
98- },
99- },
100- }
101-
10293 if token != "" {
10394 tokens := strings .Split (token , "," )
10495 for _ , token := range tokens {
10596 token = strings .TrimSpace (token )
106-
10797 ts := oauth2 .StaticTokenSource (
10898 & oauth2.Token {AccessToken : token },
10999 )
110- client = oauth2 .NewClient (downloader .ctx , ts )
100+ var client = & http.Client {
101+ Transport : & oauth2.Transport {
102+ Base : & http.Transport {
103+ TLSClientConfig : & tls.Config {InsecureSkipVerify : setting .Migrations .SkipTLSVerify },
104+ Proxy : func (req * http.Request ) (* url.URL , error ) {
105+ return proxy .Proxy ()(req )
106+ },
107+ },
108+ Source : oauth2 .ReuseTokenSource (nil , ts ),
109+ },
110+ }
111111
112112 downloader .addClient (client , baseURL )
113113 }
114114 } else {
115+ var client = & http.Client {
116+ Transport : & http.Transport {
117+ TLSClientConfig : & tls.Config {InsecureSkipVerify : setting .Migrations .SkipTLSVerify },
118+ Proxy : func (req * http.Request ) (* url.URL , error ) {
119+ req .SetBasicAuth (userName , password )
120+ return proxy .Proxy ()(req )
121+ },
122+ },
123+ }
115124 downloader .addClient (client , baseURL )
116125 }
117126 return & downloader
@@ -131,7 +140,7 @@ func (g *GithubDownloaderV3) SetContext(ctx context.Context) {
131140 g .ctx = ctx
132141}
133142
134- func (g * GithubDownloaderV3 ) sleep () {
143+ func (g * GithubDownloaderV3 ) waitAndPickClient () {
135144 var recentIdx int
136145 var maxRemaining int
137146 for i := 0 ; i < len (g .clients ); i ++ {
@@ -184,7 +193,7 @@ func (g *GithubDownloaderV3) setRate(rate *github.Rate) {
184193
185194// GetRepoInfo returns a repository information
186195func (g * GithubDownloaderV3 ) GetRepoInfo () (* base.Repository , error ) {
187- g .sleep ()
196+ g .waitAndPickClient ()
188197 gr , resp , err := g .getClient ().Repositories .Get (g .ctx , g .repoOwner , g .repoName )
189198 if err != nil {
190199 return nil , err
@@ -205,7 +214,7 @@ func (g *GithubDownloaderV3) GetRepoInfo() (*base.Repository, error) {
205214
206215// GetTopics return github topics
207216func (g * GithubDownloaderV3 ) GetTopics () ([]string , error ) {
208- g .sleep ()
217+ g .waitAndPickClient ()
209218 r , resp , err := g .getClient ().Repositories .Get (g .ctx , g .repoOwner , g .repoName )
210219 if err != nil {
211220 return nil , err
@@ -219,7 +228,7 @@ func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) {
219228 var perPage = g .maxPerPage
220229 var milestones = make ([]* base.Milestone , 0 , perPage )
221230 for i := 1 ; ; i ++ {
222- g .sleep ()
231+ g .waitAndPickClient ()
223232 ms , resp , err := g .getClient ().Issues .ListMilestones (g .ctx , g .repoOwner , g .repoName ,
224233 & github.MilestoneListOptions {
225234 State : "all" ,
@@ -267,7 +276,7 @@ func (g *GithubDownloaderV3) GetLabels() ([]*base.Label, error) {
267276 var perPage = g .maxPerPage
268277 var labels = make ([]* base.Label , 0 , perPage )
269278 for i := 1 ; ; i ++ {
270- g .sleep ()
279+ g .waitAndPickClient ()
271280 ls , resp , err := g .getClient ().Issues .ListLabels (g .ctx , g .repoOwner , g .repoName ,
272281 & github.ListOptions {
273282 Page : i ,
@@ -324,7 +333,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
324333 Created : asset .CreatedAt .Time ,
325334 Updated : asset .UpdatedAt .Time ,
326335 DownloadFunc : func () (io.ReadCloser , error ) {
327- g .sleep ()
336+ g .waitAndPickClient ()
328337 asset , redirectURL , err := g .getClient ().Repositories .DownloadReleaseAsset (g .ctx , g .repoOwner , g .repoName , assetID , nil )
329338 if err != nil {
330339 return nil , err
@@ -334,7 +343,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
334343 }
335344 if asset == nil {
336345 if redirectURL != "" {
337- g .sleep ()
346+ g .waitAndPickClient ()
338347 req , err := http .NewRequestWithContext (g .ctx , "GET" , redirectURL , nil )
339348 if err != nil {
340349 return nil , err
@@ -363,7 +372,7 @@ func (g *GithubDownloaderV3) GetReleases() ([]*base.Release, error) {
363372 var perPage = g .maxPerPage
364373 var releases = make ([]* base.Release , 0 , perPage )
365374 for i := 1 ; ; i ++ {
366- g .sleep ()
375+ g .waitAndPickClient ()
367376 ls , resp , err := g .getClient ().Repositories .ListReleases (g .ctx , g .repoOwner , g .repoName ,
368377 & github.ListOptions {
369378 Page : i ,
@@ -400,7 +409,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
400409 }
401410
402411 var allIssues = make ([]* base.Issue , 0 , perPage )
403- g .sleep ()
412+ g .waitAndPickClient ()
404413 issues , resp , err := g .getClient ().Issues .ListByRepo (g .ctx , g .repoOwner , g .repoName , opt )
405414 if err != nil {
406415 return nil , false , fmt .Errorf ("error while listing repos: %v" , err )
@@ -420,7 +429,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
420429 // get reactions
421430 var reactions []* base.Reaction
422431 for i := 1 ; ; i ++ {
423- g .sleep ()
432+ g .waitAndPickClient ()
424433 res , resp , err := g .getClient ().Reactions .ListIssueReactions (g .ctx , g .repoOwner , g .repoName , issue .GetNumber (), & github.ListOptions {
425434 Page : i ,
426435 PerPage : perPage ,
@@ -498,7 +507,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
498507 },
499508 }
500509 for {
501- g .sleep ()
510+ g .waitAndPickClient ()
502511 comments , resp , err := g .getClient ().Issues .ListComments (g .ctx , g .repoOwner , g .repoName , int (issueContext .ForeignID ()), opt )
503512 if err != nil {
504513 return nil , fmt .Errorf ("error while listing repos: %v" , err )
@@ -508,7 +517,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
508517 // get reactions
509518 var reactions []* base.Reaction
510519 for i := 1 ; ; i ++ {
511- g .sleep ()
520+ g .waitAndPickClient ()
512521 res , resp , err := g .getClient ().Reactions .ListIssueCommentReactions (g .ctx , g .repoOwner , g .repoName , comment .GetID (), & github.ListOptions {
513522 Page : i ,
514523 PerPage : g .maxPerPage ,
@@ -567,7 +576,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
567576 },
568577 }
569578
570- g .sleep ()
579+ g .waitAndPickClient ()
571580 comments , resp , err := g .getClient ().Issues .ListComments (g .ctx , g .repoOwner , g .repoName , 0 , opt )
572581 if err != nil {
573582 return nil , false , fmt .Errorf ("error while listing repos: %v" , err )
@@ -580,7 +589,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
580589 // get reactions
581590 var reactions []* base.Reaction
582591 for i := 1 ; ; i ++ {
583- g .sleep ()
592+ g .waitAndPickClient ()
584593 res , resp , err := g .getClient ().Reactions .ListIssueCommentReactions (g .ctx , g .repoOwner , g .repoName , comment .GetID (), & github.ListOptions {
585594 Page : i ,
586595 PerPage : g .maxPerPage ,
@@ -632,7 +641,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
632641 },
633642 }
634643 var allPRs = make ([]* base.PullRequest , 0 , perPage )
635- g .sleep ()
644+ g .waitAndPickClient ()
636645 prs , resp , err := g .getClient ().PullRequests .List (g .ctx , g .repoOwner , g .repoName , opt )
637646 if err != nil {
638647 return nil , false , fmt .Errorf ("error while listing repos: %v" , err )
@@ -648,7 +657,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
648657 // get reactions
649658 var reactions []* base.Reaction
650659 for i := 1 ; ; i ++ {
651- g .sleep ()
660+ g .waitAndPickClient ()
652661 res , resp , err := g .getClient ().Reactions .ListIssueReactions (g .ctx , g .repoOwner , g .repoName , pr .GetNumber (), & github.ListOptions {
653662 Page : i ,
654663 PerPage : perPage ,
@@ -669,6 +678,9 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
669678 }
670679 }
671680
681+ // download patch and saved as tmp file
682+ g .waitAndPickClient ()
683+
672684 allPRs = append (allPRs , & base.PullRequest {
673685 Title : pr .GetTitle (),
674686 Number : int64 (pr .GetNumber ()),
@@ -726,7 +738,7 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
726738 // get reactions
727739 var reactions []* base.Reaction
728740 for i := 1 ; ; i ++ {
729- g .sleep ()
741+ g .waitAndPickClient ()
730742 res , resp , err := g .getClient ().Reactions .ListPullRequestCommentReactions (g .ctx , g .repoOwner , g .repoName , c .GetID (), & github.ListOptions {
731743 Page : i ,
732744 PerPage : g .maxPerPage ,
@@ -771,7 +783,7 @@ func (g *GithubDownloaderV3) GetReviews(context base.IssueContext) ([]*base.Revi
771783 PerPage : g .maxPerPage ,
772784 }
773785 for {
774- g .sleep ()
786+ g .waitAndPickClient ()
775787 reviews , resp , err := g .getClient ().PullRequests .ListReviews (g .ctx , g .repoOwner , g .repoName , int (context .ForeignID ()), opt )
776788 if err != nil {
777789 return nil , fmt .Errorf ("error while listing repos: %v" , err )
@@ -785,7 +797,7 @@ func (g *GithubDownloaderV3) GetReviews(context base.IssueContext) ([]*base.Revi
785797 PerPage : g .maxPerPage ,
786798 }
787799 for {
788- g .sleep ()
800+ g .waitAndPickClient ()
789801 reviewComments , resp , err := g .getClient ().PullRequests .ListReviewComments (g .ctx , g .repoOwner , g .repoName , int (context .ForeignID ()), review .GetID (), opt2 )
790802 if err != nil {
791803 return nil , fmt .Errorf ("error while listing repos: %v" , err )
0 commit comments