Skip to content

Commit d610f62

Browse files
committed
fix(import[github]) Fix truncation warning at full-page boundary
why: When count reached the limit on the last item of a full page, the for-loop ended naturally — the count guard never fired, so more_available stayed False and no truncation warning was emitted. what: - Add post-loop boundary check in _paginate_repos - Add test_github_truncation_at_page_boundary covering the edge case
1 parent 92fbc04 commit d610f62

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/vcspull/_internal/remotes/github.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ def _paginate_repos(
314314
yield repo
315315
count += 1
316316

317+
# Boundary: limit reached on the last item of a full page
318+
if count >= options.limit and len(data) == DEFAULT_PER_PAGE:
319+
more_available = True
320+
break
321+
317322
# Check if there are more pages
318323
if len(data) < DEFAULT_PER_PAGE:
319324
break

tests/_internal/remotes/test_github.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,3 +779,44 @@ def urlopen_side_effect(
779779
assert expected_warning_fragment in caplog.text.lower()
780780
else:
781781
assert "--limit" not in caplog.text.lower()
782+
783+
784+
def test_github_truncation_at_page_boundary(
785+
monkeypatch: pytest.MonkeyPatch,
786+
caplog: pytest.LogCaptureFixture,
787+
) -> None:
788+
"""Truncation warning fires when limit equals a full page of results."""
789+
import logging
790+
791+
from tests._internal.remotes.conftest import MockHTTPResponse
792+
793+
# Return exactly DEFAULT_PER_PAGE (100) repos on page 1;
794+
# the while loop should detect this boundary and warn
795+
page1_repos = [_make_github_repo(i) for i in range(100)]
796+
page2_repos = [_make_github_repo(i) for i in range(100, 105)]
797+
rate_headers = {"x-ratelimit-remaining": "100", "x-ratelimit-limit": "60"}
798+
799+
call_count = 0
800+
801+
def urlopen_side_effect(
802+
request: t.Any,
803+
timeout: int | None = None,
804+
) -> MockHTTPResponse:
805+
nonlocal call_count
806+
call_count += 1
807+
if call_count == 1:
808+
body = json.dumps(page1_repos).encode()
809+
else:
810+
body = json.dumps(page2_repos).encode()
811+
return MockHTTPResponse(body, rate_headers, 200)
812+
813+
monkeypatch.setattr("urllib.request.urlopen", urlopen_side_effect)
814+
caplog.set_level(logging.WARNING)
815+
816+
importer = GitHubImporter()
817+
options = ImportOptions(mode=ImportMode.USER, target="user", limit=100)
818+
repos = list(importer.fetch_repos(options))
819+
820+
assert len(repos) == 100
821+
assert call_count == 1, "Should not fetch page 2 when limit already reached"
822+
assert "more may be available" in caplog.text.lower()

0 commit comments

Comments
 (0)