@@ -100,10 +100,7 @@ func (s *giteaRepoService) Get(ctx context.Context, owner, repo string) (*forge.
100100}
101101
102102func (s * giteaRepoService ) List (ctx context.Context , owner string , opts forge.ListRepoOpts ) ([]forge.Repository , error ) {
103- perPage := opts .PerPage
104- if perPage <= 0 {
105- perPage = defaultPageSize
106- }
103+ perPage := pageSize (opts .PerPage )
107104
108105 // Try org endpoint first, fall back to user on 404.
109106 repos , err := s .listOrgRepos (ctx , owner , perPage )
@@ -133,7 +130,7 @@ func (s *giteaRepoService) listOrgRepos(_ context.Context, owner string, perPage
133130 for _ , r := range gRepos {
134131 all = append (all , convertGiteaRepo (r ))
135132 }
136- if len (gRepos ) < perPage {
133+ if lastPage ( resp , len (gRepos ), perPage ) {
137134 break
138135 }
139136 page ++
@@ -157,7 +154,7 @@ func (s *giteaRepoService) listUserRepos(_ context.Context, owner string, perPag
157154 for _ , r := range gRepos {
158155 all = append (all , convertGiteaRepo (r ))
159156 }
160- if len (gRepos ) < perPage {
157+ if lastPage ( resp , len (gRepos ), perPage ) {
161158 break
162159 }
163160 page ++
@@ -300,10 +297,7 @@ func (s *giteaRepoService) Fork(ctx context.Context, owner, repo string, opts fo
300297}
301298
302299func (s * giteaRepoService ) ListForks (ctx context.Context , owner , repo string , opts forge.ListForksOpts ) ([]forge.Repository , error ) {
303- perPage := opts .PerPage
304- if perPage <= 0 {
305- perPage = defaultPageSize
306- }
300+ perPage := pageSize (opts .PerPage )
307301 page := opts .Page
308302 if page <= 0 {
309303 page = 1
@@ -323,7 +317,7 @@ func (s *giteaRepoService) ListForks(ctx context.Context, owner, repo string, op
323317 for _ , r := range forks {
324318 all = append (all , convertGiteaRepo (r ))
325319 }
326- if len (forks ) < perPage || (opts .Limit > 0 && len (all ) >= opts .Limit ) {
320+ if lastPage ( resp , len (forks ), perPage ) || (opts .Limit > 0 && len (all ) >= opts .Limit ) {
327321 break
328322 }
329323 page ++
@@ -369,10 +363,7 @@ func (s *giteaRepoService) ListContributors(ctx context.Context, owner, repo str
369363}
370364
371365func (s * giteaRepoService ) Search (ctx context.Context , opts forge.SearchRepoOpts ) ([]forge.Repository , error ) {
372- perPage := opts .PerPage
373- if perPage <= 0 {
374- perPage = 30
375- }
366+ perPage := pageSize (opts .PerPage )
376367 page := opts .Page
377368 if page <= 0 {
378369 page = 1
0 commit comments