diff --git a/codecov_cli/helpers/versioning_systems.py b/codecov_cli/helpers/versioning_systems.py index 856778cf..c4e44cc8 100644 --- a/codecov_cli/helpers/versioning_systems.py +++ b/codecov_cli/helpers/versioning_systems.py @@ -1,3 +1,4 @@ +from itertools import chain import logging import subprocess import typing as t @@ -10,6 +11,41 @@ logger = logging.getLogger("codecovcli") +IGNORE_DIRS = [ + '*.egg-info', + '.DS_Store', + '.circleci', + '.env', + '.envs', + '.git', + '.gitignore', + '.mypy_cache', + '.nvmrc', + '.nyc_output', + '.ruff_cache', + '.venv', + '.venvns', + '.virtualenv', + '.virtualenvs', + '__pycache__', + 'bower_components', + 'build/lib/', + 'jspm_packages', + 'node_modules', + 'vendor', + 'virtualenv', + 'virtualenvs', +] + +IGNORE_PATHS = [ + '*.gif', + '*.jpeg', + '*.jpg', + '*.md', + '*.png', + 'shunit2*', +] + class VersioningSystemInterface(ABC): def __repr__(self) -> str: @@ -161,4 +197,18 @@ def get_fallback_value(self, fallback_field: FallbackFieldEnum): def list_relevant_files( self, directory: t.Optional[Path] = None, recurse_submodules: bool = False ) -> t.List[str]: - return [] + dir_to_use = directory or self.get_network_root() + if dir_to_use is None: + raise ValueError("Can't determine root folder") + + cmd = [ + "find", + dir_to_use, + *chain.from_iterable(["-name", block, "-prune", "-o"] for block in IGNORE_DIRS), + *chain.from_iterable(["-path", block, "-prune", "-o"] for block in IGNORE_PATHS), + "-type", + "f", + "-print", + ] + res = subprocess.run(cmd, capture_output=True) + return [filename for filename in res.stdout.decode("unicode_escape").strip().split("\n") if filename] diff --git a/tests/services/upload/test_upload_collector.py b/tests/services/upload/test_upload_collector.py index c3aeca26..5e383e9f 100644 --- a/tests/services/upload/test_upload_collector.py +++ b/tests/services/upload/test_upload_collector.py @@ -194,13 +194,26 @@ def test_generate_upload_data_with_none_network( res = collector.generate_upload_data() mock_logger.debug.assert_any_call("Collecting relevant files") - mock_logger.debug.assert_any_call( - "Found 0 network files to report, (0 without filtering)" - ) mock_logger.info.assert_any_call("Found 1 coverage files to report") mock_logger.info.assert_any_call("> {}".format(tmp_path / "coverage.xml")) - assert res.network == [] + assert len(res.network) > 1 assert len(res.files) == 1 - assert len(res.file_fixes) == 0 + assert len(res.file_fixes) > 1 + +@patch("codecov_cli.services.upload.upload_collector.logger") +@patch.object(GitVersioningSystem, "get_network_root", return_value=None) +def test_generate_network_with_no_versioning_system( + mock_get_network_root, mock_logger, tmp_path +): + versioning_system = NoVersioningSystem() + found_files = versioning_system.list_relevant_files() + assert len(found_files) > 1 + + found_files = versioning_system.list_relevant_files(tmp_path) + assert len(found_files) == 0 + + (tmp_path / "coverage.xml").touch() + found_files = versioning_system.list_relevant_files(tmp_path) + assert len(found_files) == 1