Skip to content

Commit 69e4250

Browse files
committed
fix(import[gitlab]) Emit qualified warning when client filters reduce count below limit
why: The count < limit early return in _warn_truncation suppressed the qualified warning whenever filters excluded enough repos to keep count under the limit, even when total_available exceeded count. what: - Skip early return when has_client_filters=True so total_available > count can still trigger the qualified warning - Update _warn_truncation docstring to explain new semantics - Add test_gitlab_truncation_warning_count_below_limit_with_filters
1 parent 72771d8 commit 69e4250

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

src/vcspull/_internal/remotes/gitlab.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,16 @@ def _warn_truncation(
367367
x_next_page : str | None
368368
Value of x-next-page header (None if absent/empty)
369369
has_client_filters : bool
370-
True when any client-side filter (skip_groups, language, topics) is
371-
active; used to qualify the warning message so the server-side
372-
total is not presented as the filtered total.
370+
True when any client-side filter (skip_groups, language, topics,
371+
min_stars) is active; suppresses the early ``count < limit`` return
372+
so the qualified warning can fire even when count < limit.
373373
"""
374-
if count < limit:
374+
# Without client-side filters, count < limit means we consumed all
375+
# server results without hitting the limit — no truncation to warn about.
376+
# With active filters, skip the early return: count < limit may simply
377+
# reflect that filters excluded repos, while total_available still
378+
# exceeds count and is worth surfacing to the user.
379+
if count < limit and not has_client_filters:
375380
return
376381

377382
if total_available is not None and total_available > count:

tests/_internal/remotes/test_gitlab.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,45 @@ def urlopen_side_effect(
888888
assert "server total includes projects excluded" in caplog.text
889889

890890

891+
def test_gitlab_truncation_warning_count_below_limit_with_filters(
892+
monkeypatch: pytest.MonkeyPatch,
893+
caplog: pytest.LogCaptureFixture,
894+
) -> None:
895+
"""Qualified warning fires even when count < limit, if client filters are active.
896+
897+
Regression test: the count < limit early return in _warn_truncation must
898+
not suppress the warning when has_client_filters=True.
899+
"""
900+
import logging
901+
902+
caplog.set_level(logging.WARNING)
903+
904+
# _make_group_project has namespace full_path="testgroup";
905+
# skip_groups=["testgroup"] filters every repo → count=0 < limit=20
906+
repos = [_make_group_project(f"proj-{i}") for i in range(5)]
907+
headers = {"x-total": "5"}
908+
909+
def urlopen_side_effect(
910+
request: urllib.request.Request,
911+
timeout: int | None = None,
912+
) -> MockHTTPResponse:
913+
return MockHTTPResponse(json.dumps(repos).encode(), headers, 200)
914+
915+
monkeypatch.setattr("urllib.request.urlopen", urlopen_side_effect)
916+
917+
importer = GitLabImporter()
918+
options = ImportOptions(
919+
mode=ImportMode.ORG,
920+
target="testgroup",
921+
limit=20,
922+
skip_groups=["testgroup"], # owner="testgroup", so all 5 repos are excluded
923+
)
924+
list(importer.fetch_repos(options))
925+
926+
# count=0 < limit=20, but has_client_filters=True → qualified warning should fire
927+
assert "server total includes projects excluded" in caplog.text
928+
929+
891930
# ---------------------------------------------------------------------------
892931
# with_shared URL parameter tests
893932
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)