@@ -11,6 +11,7 @@ import (
1111 "io"
1212 "net/http"
1313 "net/url"
14+ "strconv"
1415 "strings"
1516 "time"
1617
@@ -450,8 +451,22 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
450451 return allIssues , len (issues ) < perPage , nil
451452}
452453
454+ // SupportGetRepoComments return true if it supports get repo comments
455+ func (g * GithubDownloaderV3 ) SupportGetRepoComments () bool {
456+ return true
457+ }
458+
453459// 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 ) {
455470 var (
456471 allComments = make ([]* base.Comment , 0 , g .maxPerPage )
457472 created = "created"
@@ -519,6 +534,75 @@ func (g *GithubDownloaderV3) GetComments(issueNumber int64) ([]*base.Comment, er
519534 return allComments , nil
520535}
521536
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+
522606// GetPullRequests returns pull requests according page and perPage
523607func (g * GithubDownloaderV3 ) GetPullRequests (page , perPage int ) ([]* base.PullRequest , bool , error ) {
524608 if perPage > g .maxPerPage {
@@ -539,6 +623,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
539623 if err != nil {
540624 return nil , false , fmt .Errorf ("error while listing repos: %v" , err )
541625 }
626+ log .Trace ("Request get pull requests %d/%d, but in fact get %d" , perPage , page , len (prs ))
542627 g .rate = & resp .Rate
543628 for _ , pr := range prs {
544629 var body string
0 commit comments