@@ -65,23 +65,25 @@ func (f *GithubDownloaderV3Factory) GitServiceType() structs.GitServiceType {
65
65
// GithubDownloaderV3 implements a Downloader interface to get repository informations
66
66
// from github via APIv3
67
67
type GithubDownloaderV3 struct {
68
- ctx context.Context
69
- client * github.Client
70
- repoOwner string
71
- repoName string
72
- userName string
73
- password string
74
- rate * github.Rate
68
+ ctx context.Context
69
+ client * github.Client
70
+ repoOwner string
71
+ repoName string
72
+ userName string
73
+ password string
74
+ rate * github.Rate
75
+ maxPerPage int
75
76
}
76
77
77
78
// NewGithubDownloaderV3 creates a github Downloader via github v3 API
78
79
func NewGithubDownloaderV3 (ctx context.Context , baseURL , userName , password , token , repoOwner , repoName string ) * GithubDownloaderV3 {
79
80
var downloader = GithubDownloaderV3 {
80
- userName : userName ,
81
- password : password ,
82
- ctx : ctx ,
83
- repoOwner : repoOwner ,
84
- repoName : repoName ,
81
+ userName : userName ,
82
+ password : password ,
83
+ ctx : ctx ,
84
+ repoOwner : repoOwner ,
85
+ repoName : repoName ,
86
+ maxPerPage : 100 ,
85
87
}
86
88
87
89
client := & http.Client {
@@ -177,7 +179,7 @@ func (g *GithubDownloaderV3) GetTopics() ([]string, error) {
177
179
178
180
// GetMilestones returns milestones
179
181
func (g * GithubDownloaderV3 ) GetMilestones () ([]* base.Milestone , error ) {
180
- var perPage = 100
182
+ var perPage = g . maxPerPage
181
183
var milestones = make ([]* base.Milestone , 0 , perPage )
182
184
for i := 1 ; ; i ++ {
183
185
g .sleep ()
@@ -233,7 +235,7 @@ func convertGithubLabel(label *github.Label) *base.Label {
233
235
234
236
// GetLabels returns labels
235
237
func (g * GithubDownloaderV3 ) GetLabels () ([]* base.Label , error ) {
236
- var perPage = 100
238
+ var perPage = g . maxPerPage
237
239
var labels = make ([]* base.Label , 0 , perPage )
238
240
for i := 1 ; ; i ++ {
239
241
g .sleep ()
@@ -304,7 +306,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
304
306
305
307
// GetReleases returns releases
306
308
func (g * GithubDownloaderV3 ) GetReleases () ([]* base.Release , error ) {
307
- var perPage = 100
309
+ var perPage = g . maxPerPage
308
310
var releases = make ([]* base.Release , 0 , perPage )
309
311
for i := 1 ; ; i ++ {
310
312
g .sleep ()
@@ -342,6 +344,9 @@ func (g *GithubDownloaderV3) GetAsset(_ string, _, id int64) (io.ReadCloser, err
342
344
343
345
// GetIssues returns issues according start and limit
344
346
func (g * GithubDownloaderV3 ) GetIssues (page , perPage int ) ([]* base.Issue , bool , error ) {
347
+ if perPage > g .maxPerPage {
348
+ perPage = g .maxPerPage
349
+ }
345
350
opt := & github.IssueListByRepoOptions {
346
351
Sort : "created" ,
347
352
Direction : "asc" ,
@@ -429,15 +434,15 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
429
434
// GetComments returns comments according issueNumber
430
435
func (g * GithubDownloaderV3 ) GetComments (issueNumber int64 ) ([]* base.Comment , error ) {
431
436
var (
432
- allComments = make ([]* base.Comment , 0 , 100 )
437
+ allComments = make ([]* base.Comment , 0 , g . maxPerPage )
433
438
created = "created"
434
439
asc = "asc"
435
440
)
436
441
opt := & github.IssueListCommentsOptions {
437
442
Sort : & created ,
438
443
Direction : & asc ,
439
444
ListOptions : github.ListOptions {
440
- PerPage : 100 ,
445
+ PerPage : g . maxPerPage ,
441
446
},
442
447
}
443
448
for {
@@ -459,7 +464,7 @@ func (g *GithubDownloaderV3) GetComments(issueNumber int64) ([]*base.Comment, er
459
464
g .sleep ()
460
465
res , resp , err := g .client .Reactions .ListIssueCommentReactions (g .ctx , g .repoOwner , g .repoName , comment .GetID (), & github.ListOptions {
461
466
Page : i ,
462
- PerPage : 100 ,
467
+ PerPage : g . maxPerPage ,
463
468
})
464
469
if err != nil {
465
470
return nil , err
@@ -497,6 +502,9 @@ func (g *GithubDownloaderV3) GetComments(issueNumber int64) ([]*base.Comment, er
497
502
498
503
// GetPullRequests returns pull requests according page and perPage
499
504
func (g * GithubDownloaderV3 ) GetPullRequests (page , perPage int ) ([]* base.PullRequest , bool , error ) {
505
+ if perPage > g .maxPerPage {
506
+ perPage = g .maxPerPage
507
+ }
500
508
opt := & github.PullRequestListOptions {
501
509
Sort : "created" ,
502
510
Direction : "asc" ,
@@ -650,7 +658,7 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
650
658
g .sleep ()
651
659
res , resp , err := g .client .Reactions .ListPullRequestCommentReactions (g .ctx , g .repoOwner , g .repoName , c .GetID (), & github.ListOptions {
652
660
Page : i ,
653
- PerPage : 100 ,
661
+ PerPage : g . maxPerPage ,
654
662
})
655
663
if err != nil {
656
664
return nil , err
@@ -687,9 +695,9 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
687
695
688
696
// GetReviews returns pull requests review
689
697
func (g * GithubDownloaderV3 ) GetReviews (pullRequestNumber int64 ) ([]* base.Review , error ) {
690
- var allReviews = make ([]* base.Review , 0 , 100 )
698
+ var allReviews = make ([]* base.Review , 0 , g . maxPerPage )
691
699
opt := & github.ListOptions {
692
- PerPage : 100 ,
700
+ PerPage : g . maxPerPage ,
693
701
}
694
702
for {
695
703
g .sleep ()
@@ -703,7 +711,7 @@ func (g *GithubDownloaderV3) GetReviews(pullRequestNumber int64) ([]*base.Review
703
711
r .IssueIndex = pullRequestNumber
704
712
// retrieve all review comments
705
713
opt2 := & github.ListOptions {
706
- PerPage : 100 ,
714
+ PerPage : g . maxPerPage ,
707
715
}
708
716
for {
709
717
g .sleep ()
0 commit comments