@@ -415,17 +415,15 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
415415 milestone = issue .Milestone .Title
416416 }
417417
418- var reactions []* base. Reaction
418+ var reactions []* gitlab. AwardEmoji
419419 awardPage := 1
420420 for {
421421 awards , _ , err := g .client .AwardEmoji .ListIssueAwardEmoji (g .repoID , issue .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
422422 if err != nil {
423423 return nil , false , fmt .Errorf ("error while listing issue awards: %w" , err )
424424 }
425425
426- for i := range awards {
427- reactions = append (reactions , g .awardToReaction (awards [i ]))
428- }
426+ reactions = append (reactions , awards ... )
429427
430428 if len (awards ) < perPage {
431429 break
@@ -444,7 +442,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
444442 State : issue .State ,
445443 Created : * issue .CreatedAt ,
446444 Labels : labels ,
447- Reactions : reactions ,
445+ Reactions : g . awardsToReactions ( reactions ) ,
448446 Closed : issue .ClosedAt ,
449447 IsLocked : issue .DiscussionLocked ,
450448 Updated : * issue .UpdatedAt ,
@@ -579,17 +577,15 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
579577 milestone = pr .Milestone .Title
580578 }
581579
582- var reactions []* base. Reaction
580+ var reactions []* gitlab. AwardEmoji
583581 awardPage := 1
584582 for {
585583 awards , _ , err := g .client .AwardEmoji .ListMergeRequestAwardEmoji (g .repoID , pr .IID , & gitlab.ListAwardEmojiOptions {Page : awardPage , PerPage : perPage }, gitlab .WithContext (g .ctx ))
586584 if err != nil {
587585 return nil , false , fmt .Errorf ("error while listing merge requests awards: %w" , err )
588586 }
589587
590- for i := range awards {
591- reactions = append (reactions , g .awardToReaction (awards [i ]))
592- }
588+ reactions = append (reactions , awards ... )
593589
594590 if len (awards ) < perPage {
595591 break
@@ -616,7 +612,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
616612 MergeCommitSHA : pr .MergeCommitSHA ,
617613 MergedTime : mergeTime ,
618614 IsLocked : locked ,
619- Reactions : reactions ,
615+ Reactions : g . awardsToReactions ( reactions ) ,
620616 Head : base.PullRequestBranch {
621617 Ref : pr .SourceBranch ,
622618 SHA : pr .SHA ,
@@ -677,10 +673,19 @@ func (g *GitlabDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Revie
677673 return reviews , nil
678674}
679675
680- func (g * GitlabDownloader ) awardToReaction (award * gitlab.AwardEmoji ) * base.Reaction {
681- return & base.Reaction {
682- UserID : int64 (award .User .ID ),
683- UserName : award .User .Username ,
684- Content : award .Name ,
676+ func (g * GitlabDownloader ) awardsToReactions (awards []* gitlab.AwardEmoji ) []* base.Reaction {
677+ result := make ([]* base.Reaction , 0 , len (awards ))
678+ uniqCheck := make (map [string ]struct {})
679+ for _ , award := range awards {
680+ uid := fmt .Sprintf ("%s%d" , award .Name , award .User .ID )
681+ if _ , ok := uniqCheck [uid ]; ! ok {
682+ result = append (result , & base.Reaction {
683+ UserID : int64 (award .User .ID ),
684+ UserName : award .User .Username ,
685+ Content : award .Name ,
686+ })
687+ uniqCheck [uid ] = struct {}{}
688+ }
685689 }
690+ return result
686691}
0 commit comments