Skip to content

Commit 3a054ec

Browse files
committed
fix(import[gitlab]) Include --min-stars in has_client_filters qualified-warning gate
why: filter_repo() applies min_stars as a pure client-side filter, but has_client_filters omitted it; when min_stars is set the warning message was unqualified, falsely implying the server total equals the filtered total. what: - Add options.min_stars > 0 to has_client_filters in _paginate_repos and _fetch_search - Add --min-stars to the qualified warning message text - Add test_gitlab_truncation_warning_with_min_stars_filter
1 parent 69e4250 commit 3a054ec

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/vcspull/_internal/remotes/gitlab.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ def _fetch_search(self, options: ImportOptions) -> t.Iterator[RemoteRepo]:
247247
total_available,
248248
last_x_next_page,
249249
has_client_filters=bool(
250-
options.skip_groups or options.language or options.topics
250+
options.skip_groups
251+
or options.language
252+
or options.topics
253+
or options.min_stars > 0
251254
),
252255
)
253256

@@ -339,7 +342,10 @@ def _paginate_repos(
339342
total_available,
340343
last_x_next_page,
341344
has_client_filters=bool(
342-
options.skip_groups or options.language or options.topics
345+
options.skip_groups
346+
or options.language
347+
or options.topics
348+
or options.min_stars > 0
343349
),
344350
)
345351

@@ -384,7 +390,7 @@ def _warn_truncation(
384390
log.warning(
385391
"Showing %d repositories; %d total on server "
386392
"(note: server total includes projects excluded by "
387-
"--skip-group / --language / --topics; "
393+
"--skip-group / --language / --topics / --min-stars; "
388394
"use --limit 0 to fetch all matching your filters)",
389395
count,
390396
total_available,

tests/_internal/remotes/test_gitlab.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,44 @@ def urlopen_side_effect(
927927
assert "server total includes projects excluded" in caplog.text
928928

929929

930+
def test_gitlab_truncation_warning_with_min_stars_filter(
931+
monkeypatch: pytest.MonkeyPatch,
932+
caplog: pytest.LogCaptureFixture,
933+
) -> None:
934+
"""Qualified warning fires when min_stars filters repos and server total > count.
935+
936+
Regression test: min_stars must be included in the has_client_filters gate.
937+
"""
938+
import logging
939+
940+
caplog.set_level(logging.WARNING)
941+
942+
# _make_group_project has star_count=0; min_stars=1 filters all of them out
943+
repos = [_make_group_project(f"proj-{i}") for i in range(5)]
944+
headers = {"x-total": "5"}
945+
946+
def urlopen_side_effect(
947+
request: urllib.request.Request,
948+
timeout: int | None = None,
949+
) -> MockHTTPResponse:
950+
return MockHTTPResponse(json.dumps(repos).encode(), headers, 200)
951+
952+
monkeypatch.setattr("urllib.request.urlopen", urlopen_side_effect)
953+
954+
importer = GitLabImporter()
955+
options = ImportOptions(
956+
mode=ImportMode.ORG,
957+
target="testgroup",
958+
limit=20,
959+
min_stars=1, # all repos have 0 stars → all filtered out by filter_repo
960+
)
961+
list(importer.fetch_repos(options))
962+
963+
# min_stars > 0 → has_client_filters=True → qualified warning fires
964+
assert "server total includes projects excluded" in caplog.text
965+
assert "--min-stars" in caplog.text
966+
967+
930968
# ---------------------------------------------------------------------------
931969
# with_shared URL parameter tests
932970
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)