Skip to content

Commit 3461e21

Browse files
committed
fix reactions
1 parent 579ef41 commit 3461e21

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

modules/migrations/base/review.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type ReviewComment struct {
3838
Position int
3939
CommitID string
4040
PosterID int64
41-
Reactions *Reactions
41+
Reactions []*Reaction
4242
CreatedAt time.Time
4343
UpdatedAt time.Time
4444
}

modules/migrations/github.go

+33-4
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,33 @@ func convertGithubReview(r *github.PullRequestReview) *base.Review {
631631
}
632632
}
633633

634-
func convertGithubReviewComments(cs []*github.PullRequestComment) []*base.ReviewComment {
634+
func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullRequestComment) ([]*base.ReviewComment,error) {
635635
var rcs = make([]*base.ReviewComment, 0, len(cs))
636636
for _, c := range cs {
637+
// get reactions
638+
var reactions []*base.Reaction
639+
for i := 1; ; i++ {
640+
g.sleep()
641+
res, resp, err := g.client.Reactions.ListIssueCommentReactions(g.ctx, g.repoOwner, g.repoName, c.GetID(), &github.ListOptions{
642+
Page: i,
643+
PerPage: 100,
644+
})
645+
if err != nil {
646+
return nil, err
647+
}
648+
g.rate = &resp.Rate
649+
if len(res) == 0 {
650+
break
651+
}
652+
for _, reaction := range res {
653+
reactions = append(reactions, &base.Reaction{
654+
UserID: reaction.User.GetID(),
655+
UserName: reaction.User.GetLogin(),
656+
Content: reaction.GetContent(),
657+
})
658+
}
659+
}
660+
637661
rcs = append(rcs, &base.ReviewComment{
638662
ID: c.GetID(),
639663
InReplyTo: c.GetInReplyTo(),
@@ -643,12 +667,12 @@ func convertGithubReviewComments(cs []*github.PullRequestComment) []*base.Review
643667
Position: c.GetPosition(),
644668
CommitID: c.GetCommitID(),
645669
PosterID: c.GetUser().GetID(),
646-
Reactions: convertGithubReactions(c.Reactions),
670+
Reactions: reactions,
647671
CreatedAt: c.GetCreatedAt(),
648672
UpdatedAt: c.GetUpdatedAt(),
649673
})
650674
}
651-
return rcs
675+
return rcs,nil
652676
}
653677

654678
// GetReviews returns pull requests review
@@ -678,7 +702,12 @@ func (g *GithubDownloaderV3) GetReviews(pullRequestNumber int64) ([]*base.Review
678702
return nil, fmt.Errorf("error while listing repos: %v", err)
679703
}
680704
g.rate = &resp.Rate
681-
r.Comments = append(r.Comments, convertGithubReviewComments(reviewComments)...)
705+
706+
cs, err := g.convertGithubReviewComments(reviewComments)
707+
if err != nil {
708+
return nil, err
709+
}
710+
r.Comments = append(r.Comments, cs...)
682711
if resp.NextPage == 0 {
683712
break
684713
}

0 commit comments

Comments
 (0)