@@ -68,6 +68,10 @@ type Provider struct {
6868 cachedChangedFiles * changedfiles.ChangedFiles
6969}
7070
71+ var defaultGitlabListOptions = gitlab.ListOptions {
72+ PerPage : 100 ,
73+ }
74+
7175func (v * Provider ) Client () * gitlab.Client {
7276 providerMetrics .RecordAPIUsage (
7377 v .Logger ,
@@ -99,32 +103,46 @@ func (v *Provider) CreateComment(_ context.Context, event *info.Event, commit, u
99103
100104 // List comments of the merge request
101105 if updateMarker != "" {
102- comments , _ , err := v .Client ().Notes .ListMergeRequestNotes (event .TargetProjectID , event .PullRequestNumber , & gitlab.ListMergeRequestNotesOptions {
103- ListOptions : gitlab.ListOptions {
104- Page : 1 ,
105- PerPage : 100 ,
106- },
107- })
108- if err != nil {
109- return err
110- }
106+ commentRe := regexp .MustCompile (updateMarker )
107+ options := []gitlab.RequestOptionFunc {}
111108
112- re := regexp .MustCompile (updateMarker )
113- for _ , comment := range comments {
114- if re .MatchString (comment .Body ) {
115- _ , _ , err := v .Client ().Notes .UpdateMergeRequestNote (event .TargetProjectID , event .PullRequestNumber , comment .ID , & gitlab.UpdateMergeRequestNoteOptions {
116- Body : & commit ,
117- })
109+ for {
110+ comments , resp , err := v .Client ().Notes .ListMergeRequestNotes (event .TargetProjectID , event .PullRequestNumber , & gitlab.ListMergeRequestNotesOptions {ListOptions : defaultGitlabListOptions }, options ... )
111+ if err != nil {
118112 return err
119113 }
114+
115+ for _ , comment := range comments {
116+ if commentRe .MatchString (comment .Body ) {
117+ _ , _ , err := v .Client ().Notes .UpdateMergeRequestNote (event .TargetProjectID , event .PullRequestNumber , comment .ID , & gitlab.UpdateMergeRequestNoteOptions {
118+ Body : & commit ,
119+ })
120+ if err != nil {
121+ return fmt .Errorf ("unable to update merge request note: %w" , err )
122+ }
123+ return nil
124+ }
125+ }
126+
127+ // Exit the loop when we've seen all pages.
128+ if resp .NextLink == "" {
129+ break
130+ }
131+
132+ // Otherwise, set param to query the next page
133+ options = []gitlab.RequestOptionFunc {
134+ gitlab .WithKeysetPaginationParameters (resp .NextLink ),
135+ }
120136 }
121137 }
122138
123139 _ , _ , err := v .Client ().Notes .CreateMergeRequestNote (event .TargetProjectID , event .PullRequestNumber , & gitlab.CreateMergeRequestNoteOptions {
124140 Body : & commit ,
125141 })
126-
127- return err
142+ if err != nil {
143+ return fmt .Errorf ("unable to create merge request note: %w" , err )
144+ }
145+ return nil
128146}
129147
130148// CheckPolicyAllowing TODO: Implement ME.
@@ -386,7 +404,7 @@ func (v *Provider) GetTektonDir(_ context.Context, event *info.Event, path, prov
386404 ListOptions : gitlab.ListOptions {
387405 OrderBy : "id" ,
388406 Pagination : "keyset" ,
389- PerPage : 20 ,
407+ PerPage : defaultGitlabListOptions . PerPage ,
390408 Sort : "asc" ,
391409 },
392410 }
@@ -524,7 +542,7 @@ func (v *Provider) fetchChangedFiles(_ context.Context, runevent *info.Event) (c
524542 ListOptions : gitlab.ListOptions {
525543 OrderBy : "id" ,
526544 Pagination : "keyset" ,
527- PerPage : 20 ,
545+ PerPage : defaultGitlabListOptions . PerPage ,
528546 Sort : "asc" ,
529547 },
530548 }
@@ -564,23 +582,38 @@ func (v *Provider) fetchChangedFiles(_ context.Context, runevent *info.Event) (c
564582 }
565583 }
566584 case triggertype .Push :
567- pushChanges , _ , err := v .Client ().Commits .GetCommitDiff (v .sourceProjectID , runevent .SHA , & gitlab.GetCommitDiffOptions {})
568- if err != nil {
569- return changedfiles.ChangedFiles {}, err
570- }
571- for _ , change := range pushChanges {
572- changedFiles .All = append (changedFiles .All , change .NewPath )
573- if change .NewFile {
574- changedFiles .Added = append (changedFiles .Added , change .NewPath )
585+ options := gitlab.GetCommitDiffOptions {ListOptions : defaultGitlabListOptions }
586+ pageOpts := []gitlab.RequestOptionFunc {}
587+
588+ for {
589+ pushChanges , resp , err := v .Client ().Commits .GetCommitDiff (v .sourceProjectID , runevent .SHA , & options , pageOpts ... )
590+ if err != nil {
591+ return changedfiles.ChangedFiles {}, err
575592 }
576- if change .DeletedFile {
577- changedFiles .Deleted = append (changedFiles .Deleted , change .NewPath )
593+
594+ for _ , change := range pushChanges {
595+ changedFiles .All = append (changedFiles .All , change .NewPath )
596+ if change .NewFile {
597+ changedFiles .Added = append (changedFiles .Added , change .NewPath )
598+ }
599+ if change .DeletedFile {
600+ changedFiles .Deleted = append (changedFiles .Deleted , change .NewPath )
601+ }
602+ if ! change .RenamedFile && ! change .DeletedFile && ! change .NewFile {
603+ changedFiles .Modified = append (changedFiles .Modified , change .NewPath )
604+ }
605+ if change .RenamedFile {
606+ changedFiles .Renamed = append (changedFiles .Renamed , change .NewPath )
607+ }
578608 }
579- if ! change .RenamedFile && ! change .DeletedFile && ! change .NewFile {
580- changedFiles .Modified = append (changedFiles .Modified , change .NewPath )
609+
610+ if resp .NextLink == "" {
611+ // Exit the loop when we've seen all pages.
612+ break
581613 }
582- if change .RenamedFile {
583- changedFiles .Renamed = append (changedFiles .Renamed , change .NewPath )
614+ // Otherwise, set param to query the next page
615+ pageOpts = []gitlab.RequestOptionFunc {
616+ gitlab .WithKeysetPaginationParameters (resp .NextLink ),
584617 }
585618 }
586619 default :
0 commit comments