Skip to content

Commit 6312280

Browse files
committed
_internal/remotes/gitea(fix[pagination]) Fix early termination in pagination
why: Comparing len(items) < DEFAULT_PER_PAGE causes premature exit when actual page_limit is smaller near the limit what: - Store page_limit value before use in _fetch_search - Compare against actual page_limit instead of DEFAULT_PER_PAGE - Apply same fix to _paginate_repos
1 parent 2d03851 commit 6312280

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/vcspull/_internal/remotes/gitea.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ def _fetch_search(self, options: ImportOptions) -> t.Iterator[RemoteRepo]:
168168
count = 0
169169

170170
while count < options.limit:
171+
page_limit = min(DEFAULT_PER_PAGE, options.limit - count)
171172
params: dict[str, str | int] = {
172173
"q": options.target,
173-
"limit": min(DEFAULT_PER_PAGE, options.limit - count),
174+
"limit": page_limit,
174175
"page": page,
175176
"sort": "stars",
176177
"order": "desc",
@@ -204,7 +205,7 @@ def _fetch_search(self, options: ImportOptions) -> t.Iterator[RemoteRepo]:
204205
count += 1
205206

206207
# Check if there are more pages
207-
if len(items) < DEFAULT_PER_PAGE:
208+
if len(items) < page_limit:
208209
break
209210

210211
page += 1
@@ -232,8 +233,9 @@ def _paginate_repos(
232233
count = 0
233234

234235
while count < options.limit:
236+
page_limit = min(DEFAULT_PER_PAGE, options.limit - count)
235237
params: dict[str, str | int] = {
236-
"limit": min(DEFAULT_PER_PAGE, options.limit - count),
238+
"limit": page_limit,
237239
"page": page,
238240
}
239241

@@ -256,7 +258,7 @@ def _paginate_repos(
256258
count += 1
257259

258260
# Check if there are more pages
259-
if len(data) < DEFAULT_PER_PAGE:
261+
if len(data) < page_limit:
260262
break
261263

262264
page += 1

0 commit comments

Comments
 (0)