@@ -434,21 +434,11 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
434
434
milestone = issue .Milestone .Title
435
435
}
436
436
437
- var reactions []* gitlab.AwardEmoji
438
- awardPage := 1
439
- for {
440
- awards , _ , err := g .client .AwardEmoji .ListIssueAwardEmoji (g .repoID , issue .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
441
- if err != nil {
442
- return nil , false , fmt .Errorf ("error while listing issue awards: %w" , err )
443
- }
444
-
445
- reactions = append (reactions , awards ... )
446
-
447
- if len (awards ) < perPage {
448
- break
449
- }
450
-
451
- awardPage ++
437
+ reactions , err := g .loadAwards (func (awardPage int ) ([]* gitlab.AwardEmoji , * gitlab.Response , error ) {
438
+ return g .client .AwardEmoji .ListIssueAwardEmoji (g .repoID , issue .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
439
+ })
440
+ if err != nil {
441
+ return nil , false , err
452
442
}
453
443
454
444
allIssues = append (allIssues , & base.Issue {
@@ -461,7 +451,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
461
451
State : issue .State ,
462
452
Created : * issue .CreatedAt ,
463
453
Labels : labels ,
464
- Reactions : g . awardsToReactions ( reactions ) ,
454
+ Reactions : reactions ,
465
455
Closed : issue .ClosedAt ,
466
456
IsLocked : issue .DiscussionLocked ,
467
457
Updated : * issue .UpdatedAt ,
@@ -477,7 +467,6 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
477
467
}
478
468
479
469
// GetComments returns comments according issueNumber
480
- // TODO: figure out how to transfer comment reactions
481
470
func (g * GitlabDownloader ) GetComments (commentable base.Commentable ) ([]* base.Comment , bool , error ) {
482
471
context , ok := commentable .GetContext ().(gitlabIssueContext )
483
472
if ! ok {
@@ -509,7 +498,18 @@ func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Co
509
498
}
510
499
for _ , comment := range comments {
511
500
for _ , note := range comment .Notes {
512
- allComments = append (allComments , g .convertNoteToComment (commentable .GetLocalIndex (), note ))
501
+ reactions , err := g .loadAwards (func (awardPage int ) ([]* gitlab.AwardEmoji , * gitlab.Response , error ) {
502
+ if context .IsMergeRequest {
503
+ return g .client .AwardEmoji .ListMergeRequestAwardEmojiOnNote (g .repoID , note .NoteableIID , note .ID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : g .maxPerPage }, gitlab .WithContext (g .ctx ))
504
+ } else {
505
+ return g .client .AwardEmoji .ListIssuesAwardEmojiOnNote (g .repoID , note .NoteableIID , note .ID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : g .maxPerPage }, gitlab .WithContext (g .ctx ))
506
+ }
507
+ })
508
+ if err != nil {
509
+ return nil , false , err
510
+ }
511
+
512
+ allComments = append (allComments , g .convertNoteToComment (commentable .GetLocalIndex (), note , reactions ))
513
513
}
514
514
}
515
515
if resp .NextPage == 0 {
@@ -576,7 +576,7 @@ func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Co
576
576
577
577
var targetBranchChangeRegexp = regexp .MustCompile ("^changed target branch from `(.*?)` to `(.*?)`$" )
578
578
579
- func (g * GitlabDownloader ) convertNoteToComment (localIndex int64 , note * gitlab.Note ) * base.Comment {
579
+ func (g * GitlabDownloader ) convertNoteToComment (localIndex int64 , note * gitlab.Note , reactions [] * base. Reaction ) * base.Comment {
580
580
comment := & base.Comment {
581
581
IssueIndex : localIndex ,
582
582
Index : int64 (note .ID ),
@@ -586,6 +586,7 @@ func (g *GitlabDownloader) convertNoteToComment(localIndex int64, note *gitlab.N
586
586
Content : note .Body ,
587
587
Created : * note .CreatedAt ,
588
588
Meta : map [string ]any {},
589
+ Reactions : reactions ,
589
590
}
590
591
591
592
// Try to find the underlying event of system notes.
@@ -671,21 +672,11 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
671
672
milestone = pr .Milestone .Title
672
673
}
673
674
674
- var reactions []* gitlab.AwardEmoji
675
- awardPage := 1
676
- for {
677
- awards , _ , err := g .client .AwardEmoji .ListMergeRequestAwardEmoji (g .repoID , pr .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
678
- if err != nil {
679
- return nil , false , fmt .Errorf ("error while listing merge requests awards: %w" , err )
680
- }
681
-
682
- reactions = append (reactions , awards ... )
683
-
684
- if len (awards ) < perPage {
685
- break
686
- }
687
-
688
- awardPage ++
675
+ reactions , err := g .loadAwards (func (awardPage int ) ([]* gitlab.AwardEmoji , * gitlab.Response , error ) {
676
+ return g .client .AwardEmoji .ListMergeRequestAwardEmoji (g .repoID , pr .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
677
+ })
678
+ if err != nil {
679
+ return nil , false , err
689
680
}
690
681
691
682
// Generate new PR Numbers by the known Issue Numbers, because they share the same number space in Gitea, but they are independent in Gitlab
@@ -706,7 +697,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
706
697
MergeCommitSHA : mergeCommitSHA ,
707
698
MergedTime : mergeTime ,
708
699
IsLocked : locked ,
709
- Reactions : g . awardsToReactions ( reactions ) ,
700
+ Reactions : reactions ,
710
701
Head : base.PullRequestBranch {
711
702
Ref : pr .SourceBranch ,
712
703
SHA : pr .SHA ,
@@ -767,6 +758,25 @@ func (g *GitlabDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Revie
767
758
return reviews , nil
768
759
}
769
760
761
+ func (g * GitlabDownloader ) loadAwards (load func (page int ) ([]* gitlab.AwardEmoji , * gitlab.Response , error )) ([]* base.Reaction , error ) {
762
+ var allAwards []* gitlab.AwardEmoji
763
+ page := 1
764
+ for {
765
+ awards , resp , err := load (page )
766
+ if err != nil {
767
+ return nil , fmt .Errorf ("error while listing awards: %w" , err )
768
+ }
769
+
770
+ allAwards = append (allAwards , awards ... )
771
+
772
+ if resp .NextPage == 0 {
773
+ break
774
+ }
775
+ page = resp .NextPage
776
+ }
777
+ return g .awardsToReactions (allAwards ), nil
778
+ }
779
+
770
780
func (g * GitlabDownloader ) awardsToReactions (awards []* gitlab.AwardEmoji ) []* base.Reaction {
771
781
result := make ([]* base.Reaction , 0 , len (awards ))
772
782
uniqCheck := make (container.Set [string ])
0 commit comments