|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import json |
| 6 | +import pathlib |
6 | 7 | import typing as t |
7 | 8 | import urllib.parse |
8 | 9 | import urllib.request |
9 | 10 |
|
10 | 11 | import pytest |
| 12 | +import yaml |
11 | 13 |
|
12 | 14 | from tests._internal.remotes.conftest import MockHTTPResponse |
13 | 15 | from vcspull._internal.remotes.base import ImportMode, ImportOptions |
14 | 16 | from vcspull._internal.remotes.gitlab import GitLabImporter |
| 17 | +from vcspull.cli.import_cmd._common import _run_import |
15 | 18 |
|
16 | 19 |
|
17 | 20 | def test_gitlab_fetch_user( |
@@ -1181,3 +1184,85 @@ def urlopen_capture( |
1181 | 1184 | assert repo_names == {"top-repo", "external-repo"}, ( |
1182 | 1185 | f"Unexpected repos returned: {repo_names}" |
1183 | 1186 | ) |
| 1187 | + |
| 1188 | + |
| 1189 | +def test_gitlab_cli_skip_groups_excludes_from_config( |
| 1190 | + mock_urlopen: t.Callable[..., None], |
| 1191 | + tmp_path: pathlib.Path, |
| 1192 | + monkeypatch: pytest.MonkeyPatch, |
| 1193 | +) -> None: |
| 1194 | + """Integration: _run_import + GitLabImporter + filter_repo writes correct config. |
| 1195 | +
|
| 1196 | + MockImporter.fetch_repos bypasses filter_repo, so CLI tests using it cannot |
| 1197 | + catch regressions in the importer→filter boundary. This test uses a real |
| 1198 | + GitLabImporter with mocked HTTP and verifies bots-repo is absent from the |
| 1199 | + written config. |
| 1200 | + """ |
| 1201 | + monkeypatch.setenv("HOME", str(tmp_path)) |
| 1202 | + |
| 1203 | + response_json: list[dict[str, t.Any]] = [ |
| 1204 | + { |
| 1205 | + "path": "top-repo", |
| 1206 | + "name": "top-repo", |
| 1207 | + "http_url_to_repo": "https://gitlab.com/testgroup/top-repo.git", |
| 1208 | + "ssh_url_to_repo": "git@gitlab.com:testgroup/top-repo.git", |
| 1209 | + "web_url": "https://gitlab.com/testgroup/top-repo", |
| 1210 | + "description": None, |
| 1211 | + "topics": [], |
| 1212 | + "star_count": 0, |
| 1213 | + "archived": False, |
| 1214 | + "default_branch": "main", |
| 1215 | + "namespace": {"path": "testgroup", "full_path": "testgroup"}, |
| 1216 | + }, |
| 1217 | + { |
| 1218 | + "path": "bots-repo", |
| 1219 | + "name": "bots-repo", |
| 1220 | + "http_url_to_repo": "https://gitlab.com/testgroup/bots/bots-repo.git", |
| 1221 | + "ssh_url_to_repo": "git@gitlab.com:testgroup/bots/bots-repo.git", |
| 1222 | + "web_url": "https://gitlab.com/testgroup/bots/bots-repo", |
| 1223 | + "description": None, |
| 1224 | + "topics": [], |
| 1225 | + "star_count": 0, |
| 1226 | + "archived": False, |
| 1227 | + "default_branch": "main", |
| 1228 | + "namespace": {"path": "bots", "full_path": "testgroup/bots"}, |
| 1229 | + }, |
| 1230 | + ] |
| 1231 | + mock_urlopen([(json.dumps(response_json).encode(), {}, 200)]) |
| 1232 | + |
| 1233 | + workspace = tmp_path / "repos" |
| 1234 | + workspace.mkdir() |
| 1235 | + config_file = tmp_path / ".vcspull.yaml" |
| 1236 | + |
| 1237 | + result = _run_import( |
| 1238 | + GitLabImporter(), |
| 1239 | + service_name="gitlab", |
| 1240 | + target="testgroup", |
| 1241 | + workspace=str(workspace), |
| 1242 | + mode="org", |
| 1243 | + language=None, |
| 1244 | + topics=None, |
| 1245 | + min_stars=0, |
| 1246 | + include_archived=False, |
| 1247 | + include_forks=False, |
| 1248 | + limit=100, |
| 1249 | + config_path_str=str(config_file), |
| 1250 | + dry_run=False, |
| 1251 | + yes=True, |
| 1252 | + output_json=False, |
| 1253 | + output_ndjson=False, |
| 1254 | + color="never", |
| 1255 | + skip_groups=["bots"], |
| 1256 | + ) |
| 1257 | + |
| 1258 | + assert result == 0 |
| 1259 | + assert config_file.exists() |
| 1260 | + config = yaml.safe_load(config_file.read_text()) |
| 1261 | + |
| 1262 | + all_repo_names: set[str] = set() |
| 1263 | + for section in config.values(): |
| 1264 | + if isinstance(section, dict): |
| 1265 | + all_repo_names.update(section.keys()) |
| 1266 | + |
| 1267 | + assert "top-repo" in all_repo_names |
| 1268 | + assert "bots-repo" not in all_repo_names |
0 commit comments