@@ -65,23 +65,25 @@ func (f *GithubDownloaderV3Factory) GitServiceType() structs.GitServiceType {
6565// GithubDownloaderV3 implements a Downloader interface to get repository informations
6666// from github via APIv3
6767type 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
7576}
7677
7778// NewGithubDownloaderV3 creates a github Downloader via github v3 API
7879func NewGithubDownloaderV3 (ctx context.Context , baseURL , userName , password , token , repoOwner , repoName string ) * GithubDownloaderV3 {
7980 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 ,
8587 }
8688
8789 client := & http.Client {
@@ -177,7 +179,7 @@ func (g *GithubDownloaderV3) GetTopics() ([]string, error) {
177179
178180// GetMilestones returns milestones
179181func (g * GithubDownloaderV3 ) GetMilestones () ([]* base.Milestone , error ) {
180- var perPage = 100
182+ var perPage = g . maxPerPage
181183 var milestones = make ([]* base.Milestone , 0 , perPage )
182184 for i := 1 ; ; i ++ {
183185 g .sleep ()
@@ -233,7 +235,7 @@ func convertGithubLabel(label *github.Label) *base.Label {
233235
234236// GetLabels returns labels
235237func (g * GithubDownloaderV3 ) GetLabels () ([]* base.Label , error ) {
236- var perPage = 100
238+ var perPage = g . maxPerPage
237239 var labels = make ([]* base.Label , 0 , perPage )
238240 for i := 1 ; ; i ++ {
239241 g .sleep ()
@@ -304,7 +306,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
304306
305307// GetReleases returns releases
306308func (g * GithubDownloaderV3 ) GetReleases () ([]* base.Release , error ) {
307- var perPage = 100
309+ var perPage = g . maxPerPage
308310 var releases = make ([]* base.Release , 0 , perPage )
309311 for i := 1 ; ; i ++ {
310312 g .sleep ()
@@ -342,6 +344,9 @@ func (g *GithubDownloaderV3) GetAsset(_ string, _, id int64) (io.ReadCloser, err
342344
343345// GetIssues returns issues according start and limit
344346func (g * GithubDownloaderV3 ) GetIssues (page , perPage int ) ([]* base.Issue , bool , error ) {
347+ if perPage > g .maxPerPage {
348+ perPage = g .maxPerPage
349+ }
345350 opt := & github.IssueListByRepoOptions {
346351 Sort : "created" ,
347352 Direction : "asc" ,
@@ -429,15 +434,15 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
429434// GetComments returns comments according issueNumber
430435func (g * GithubDownloaderV3 ) GetComments (issueNumber int64 ) ([]* base.Comment , error ) {
431436 var (
432- allComments = make ([]* base.Comment , 0 , 100 )
437+ allComments = make ([]* base.Comment , 0 , g . maxPerPage )
433438 created = "created"
434439 asc = "asc"
435440 )
436441 opt := & github.IssueListCommentsOptions {
437442 Sort : & created ,
438443 Direction : & asc ,
439444 ListOptions : github.ListOptions {
440- PerPage : 100 ,
445+ PerPage : g . maxPerPage ,
441446 },
442447 }
443448 for {
@@ -459,7 +464,7 @@ func (g *GithubDownloaderV3) GetComments(issueNumber int64) ([]*base.Comment, er
459464 g .sleep ()
460465 res , resp , err := g .client .Reactions .ListIssueCommentReactions (g .ctx , g .repoOwner , g .repoName , comment .GetID (), & github.ListOptions {
461466 Page : i ,
462- PerPage : 100 ,
467+ PerPage : g . maxPerPage ,
463468 })
464469 if err != nil {
465470 return nil , err
@@ -497,6 +502,9 @@ func (g *GithubDownloaderV3) GetComments(issueNumber int64) ([]*base.Comment, er
497502
498503// GetPullRequests returns pull requests according page and perPage
499504func (g * GithubDownloaderV3 ) GetPullRequests (page , perPage int ) ([]* base.PullRequest , bool , error ) {
505+ if perPage > g .maxPerPage {
506+ perPage = g .maxPerPage
507+ }
500508 opt := & github.PullRequestListOptions {
501509 Sort : "created" ,
502510 Direction : "asc" ,
@@ -650,7 +658,7 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
650658 g .sleep ()
651659 res , resp , err := g .client .Reactions .ListPullRequestCommentReactions (g .ctx , g .repoOwner , g .repoName , c .GetID (), & github.ListOptions {
652660 Page : i ,
653- PerPage : 100 ,
661+ PerPage : g . maxPerPage ,
654662 })
655663 if err != nil {
656664 return nil , err
@@ -687,9 +695,9 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
687695
688696// GetReviews returns pull requests review
689697func (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 )
691699 opt := & github.ListOptions {
692- PerPage : 100 ,
700+ PerPage : g . maxPerPage ,
693701 }
694702 for {
695703 g .sleep ()
@@ -703,7 +711,7 @@ func (g *GithubDownloaderV3) GetReviews(pullRequestNumber int64) ([]*base.Review
703711 r .IssueIndex = pullRequestNumber
704712 // retrieve all review comments
705713 opt2 := & github.ListOptions {
706- PerPage : 100 ,
714+ PerPage : g . maxPerPage ,
707715 }
708716 for {
709717 g .sleep ()
0 commit comments