@@ -11,6 +11,7 @@ import (
11
11
"io"
12
12
"net/http"
13
13
"net/url"
14
+ "strconv"
14
15
"strings"
15
16
"time"
16
17
@@ -450,8 +451,22 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
450
451
return allIssues , len (issues ) < perPage , nil
451
452
}
452
453
454
+ // SupportGetRepoComments return true if it supports get repo comments
455
+ func (g * GithubDownloaderV3 ) SupportGetRepoComments () bool {
456
+ return true
457
+ }
458
+
453
459
// GetComments returns comments according issueNumber
454
- func (g * GithubDownloaderV3 ) GetComments (issueNumber int64 ) ([]* base.Comment , error ) {
460
+ func (g * GithubDownloaderV3 ) GetComments (opts base.GetCommentOptions ) ([]* base.Comment , bool , error ) {
461
+ if opts .IssueNumber > 0 {
462
+ comments , err := g .getComments (opts .IssueNumber )
463
+ return comments , false , err
464
+ }
465
+
466
+ return g .GetAllComments (opts .Page , opts .PageSize )
467
+ }
468
+
469
+ func (g * GithubDownloaderV3 ) getComments (issueNumber int64 ) ([]* base.Comment , error ) {
455
470
var (
456
471
allComments = make ([]* base.Comment , 0 , g .maxPerPage )
457
472
created = "created"
@@ -519,6 +534,75 @@ func (g *GithubDownloaderV3) GetComments(issueNumber int64) ([]*base.Comment, er
519
534
return allComments , nil
520
535
}
521
536
537
+ // GetAllComments returns repository comments according page and perPageSize
538
+ func (g * GithubDownloaderV3 ) GetAllComments (page , perPage int ) ([]* base.Comment , bool , error ) {
539
+ var (
540
+ allComments = make ([]* base.Comment , 0 , perPage )
541
+ created = "created"
542
+ asc = "asc"
543
+ )
544
+ opt := & github.IssueListCommentsOptions {
545
+ Sort : & created ,
546
+ Direction : & asc ,
547
+ ListOptions : github.ListOptions {
548
+ Page : page ,
549
+ PerPage : perPage ,
550
+ },
551
+ }
552
+
553
+ g .sleep ()
554
+ comments , resp , err := g .client .Issues .ListComments (g .ctx , g .repoOwner , g .repoName , 0 , opt )
555
+ if err != nil {
556
+ return nil , false , fmt .Errorf ("error while listing repos: %v" , err )
557
+ }
558
+ log .Trace ("Request get comments %d/%d, but in fact get %d" , perPage , page , len (comments ))
559
+ g .rate = & resp .Rate
560
+ for _ , comment := range comments {
561
+ var email string
562
+ if comment .User .Email != nil {
563
+ email = * comment .User .Email
564
+ }
565
+
566
+ // get reactions
567
+ var reactions []* base.Reaction
568
+ for i := 1 ; ; i ++ {
569
+ g .sleep ()
570
+ res , resp , err := g .client .Reactions .ListIssueCommentReactions (g .ctx , g .repoOwner , g .repoName , comment .GetID (), & github.ListOptions {
571
+ Page : i ,
572
+ PerPage : g .maxPerPage ,
573
+ })
574
+ if err != nil {
575
+ return nil , false , err
576
+ }
577
+ g .rate = & resp .Rate
578
+ if len (res ) == 0 {
579
+ break
580
+ }
581
+ for _ , reaction := range res {
582
+ reactions = append (reactions , & base.Reaction {
583
+ UserID : reaction .User .GetID (),
584
+ UserName : reaction .User .GetLogin (),
585
+ Content : reaction .GetContent (),
586
+ })
587
+ }
588
+ }
589
+ idx := strings .LastIndex (* comment .IssueURL , "/" )
590
+ issueIndex , _ := strconv .ParseInt ((* comment .IssueURL )[idx + 1 :], 10 , 64 )
591
+ allComments = append (allComments , & base.Comment {
592
+ IssueIndex : issueIndex ,
593
+ PosterID : * comment .User .ID ,
594
+ PosterName : * comment .User .Login ,
595
+ PosterEmail : email ,
596
+ Content : * comment .Body ,
597
+ Created : * comment .CreatedAt ,
598
+ Updated : * comment .UpdatedAt ,
599
+ Reactions : reactions ,
600
+ })
601
+ }
602
+
603
+ return allComments , len (allComments ) < perPage , nil
604
+ }
605
+
522
606
// GetPullRequests returns pull requests according page and perPage
523
607
func (g * GithubDownloaderV3 ) GetPullRequests (page , perPage int ) ([]* base.PullRequest , bool , error ) {
524
608
if perPage > g .maxPerPage {
@@ -539,6 +623,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
539
623
if err != nil {
540
624
return nil , false , fmt .Errorf ("error while listing repos: %v" , err )
541
625
}
626
+ log .Trace ("Request get pull requests %d/%d, but in fact get %d" , perPage , page , len (prs ))
542
627
g .rate = & resp .Rate
543
628
for _ , pr := range prs {
544
629
var body string
0 commit comments