Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 81fb0d1

Browse files
fix: add list_relevant_files to NoVersioningSystem
1 parent 079f01b commit 81fb0d1

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

codecov_cli/helpers/versioning_systems.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from itertools import chain
12
import logging
23
import subprocess
34
import typing as t
@@ -148,6 +149,45 @@ def list_relevant_files(
148149

149150

150151
class NoVersioningSystem(VersioningSystemInterface):
152+
@classmethod
153+
def blockdirs(cls):
154+
return [
155+
'*.egg-info',
156+
'.DS_Store',
157+
'.circleci',
158+
'.env',
159+
'.envs',
160+
'.git',
161+
'.gitignore',
162+
'.mypy_cache',
163+
'.nvmrc',
164+
'.nyc_output',
165+
'.ruff_cache',
166+
'.venv',
167+
'.venvns',
168+
'.virtualenv',
169+
'.virtualenvs',
170+
'__pycache__',
171+
'bower_components',
172+
'build/lib/',
173+
'jspm_packages',
174+
'node_modules',
175+
'vendor',
176+
'virtualenv',
177+
'virtualenvs',
178+
]
179+
180+
@classmethod
181+
def blockfiles(cls):
182+
return [
183+
'*.gif',
184+
'*.jpeg',
185+
'*.jpg',
186+
'*.md',
187+
'*.png',
188+
'shunit2*',
189+
]
190+
151191
@classmethod
152192
def is_available(cls):
153193
return True
@@ -161,4 +201,18 @@ def get_fallback_value(self, fallback_field: FallbackFieldEnum):
161201
def list_relevant_files(
162202
self, directory: t.Optional[Path] = None, recurse_submodules: bool = False
163203
) -> t.List[str]:
164-
return []
204+
dir_to_use = directory or self.get_network_root()
205+
if dir_to_use is None:
206+
raise ValueError("Can't determine root folder")
207+
208+
cmd = [
209+
"find",
210+
dir_to_use,
211+
*list(chain(*[["-name", block, "-prune", "-o"] for block in self.__class__.blockdirs()])),
212+
*list(chain(*[["-path", block, "-prune", "-o"] for block in self.__class__.blockfiles()])),
213+
"-type",
214+
"f",
215+
"-print",
216+
]
217+
res = subprocess.run(cmd, capture_output=True)
218+
return [filename for filename in res.stdout.decode("unicode_escape").strip().split("\n") if filename]

tests/services/upload/test_upload_collector.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,28 @@ def test_generate_upload_data_with_none_network(
195195

196196
mock_logger.debug.assert_any_call("Collecting relevant files")
197197
mock_logger.debug.assert_any_call(
198-
"Found 0 network files to report, (0 without filtering)"
198+
"Found 1067 network files to report, (1067 without filtering)"
199199
)
200200

201201
mock_logger.info.assert_any_call("Found 1 coverage files to report")
202202
mock_logger.info.assert_any_call("> {}".format(tmp_path / "coverage.xml"))
203203

204-
assert res.network == []
204+
assert len(res.network) == 1067
205205
assert len(res.files) == 1
206-
assert len(res.file_fixes) == 0
206+
assert len(res.file_fixes) == 24
207+
208+
@patch("codecov_cli.services.upload.upload_collector.logger")
209+
@patch.object(GitVersioningSystem, "get_network_root", return_value=None)
210+
def test_generate_network_with_no_versioning_system(
211+
mock_get_network_root, mock_logger, tmp_path
212+
):
213+
versioning_system = NoVersioningSystem()
214+
found_files = versioning_system.list_relevant_files()
215+
assert len(found_files) == 1067
216+
217+
found_files = versioning_system.list_relevant_files(tmp_path)
218+
assert len(found_files) == 0
219+
220+
(tmp_path / "coverage.xml").touch()
221+
found_files = versioning_system.list_relevant_files(tmp_path)
222+
assert len(found_files) == 1

0 commit comments

Comments
 (0)