@@ -413,17 +413,15 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
413413 milestone = issue .Milestone .Title
414414 }
415415
416- var reactions []* base. Reaction
416+ var reactions []* gitlab. AwardEmoji
417417 awardPage := 1
418418 for {
419419 awards , _ , err := g .client .AwardEmoji .ListIssueAwardEmoji (g .repoID , issue .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
420420 if err != nil {
421421 return nil , false , fmt .Errorf ("error while listing issue awards: %w" , err )
422422 }
423423
424- for i := range awards {
425- reactions = append (reactions , g .awardToReaction (awards [i ]))
426- }
424+ reactions = append (reactions , awards ... )
427425
428426 if len (awards ) < perPage {
429427 break
@@ -442,7 +440,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
442440 State : issue .State ,
443441 Created : * issue .CreatedAt ,
444442 Labels : labels ,
445- Reactions : reactions ,
443+ Reactions : g . awardsToReactions ( reactions ) ,
446444 Closed : issue .ClosedAt ,
447445 IsLocked : issue .DiscussionLocked ,
448446 Updated : * issue .UpdatedAt ,
@@ -577,17 +575,15 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
577575 milestone = pr .Milestone .Title
578576 }
579577
580- var reactions []* base. Reaction
578+ var reactions []* gitlab. AwardEmoji
581579 awardPage := 1
582580 for {
583581 awards , _ , err := g .client .AwardEmoji .ListMergeRequestAwardEmoji (g .repoID , pr .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
584582 if err != nil {
585583 return nil , false , fmt .Errorf ("error while listing merge requests awards: %w" , err )
586584 }
587585
588- for i := range awards {
589- reactions = append (reactions , g .awardToReaction (awards [i ]))
590- }
586+ reactions = append (reactions , awards ... )
591587
592588 if len (awards ) < perPage {
593589 break
@@ -614,7 +610,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
614610 MergeCommitSHA : pr .MergeCommitSHA ,
615611 MergedTime : mergeTime ,
616612 IsLocked : locked ,
617- Reactions : reactions ,
613+ Reactions : g . awardsToReactions ( reactions ) ,
618614 Head : base.PullRequestBranch {
619615 Ref : pr .SourceBranch ,
620616 SHA : pr .SHA ,
@@ -675,10 +671,19 @@ func (g *GitlabDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Revie
675671 return reviews , nil
676672}
677673
678- func (g * GitlabDownloader ) awardToReaction (award * gitlab.AwardEmoji ) * base.Reaction {
679- return & base.Reaction {
680- UserID : int64 (award .User .ID ),
681- UserName : award .User .Username ,
682- Content : award .Name ,
674+ func (g * GitlabDownloader ) awardsToReactions (awards []* gitlab.AwardEmoji ) []* base.Reaction {
675+ result := make ([]* base.Reaction , 0 , len (awards ))
676+ uniqCheck := make (map [string ]struct {})
677+ for _ , award := range awards {
678+ uid := fmt .Sprintf ("%s%d" , award .Name , award .User .ID )
679+ if _ , ok := uniqCheck [uid ]; ! ok {
680+ result = append (result , & base.Reaction {
681+ UserID : int64 (award .User .ID ),
682+ UserName : award .User .Username ,
683+ Content : award .Name ,
684+ })
685+ uniqCheck [uid ] = struct {}{}
686+ }
683687 }
688+ return result
684689}
0 commit comments