Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Codecov-cli supports user input. These inputs, along with their descriptions and
|-s, --dir, --coverage-files-search-root-folder | Folder where to search for coverage files default: (Current Working Directory) | Optional
|--exclude, --coverage-files-search-exclude-folder | Folders to exclude from search | Optional
|-f, --file, --coverage-files-search-direct-file | Explicit files to upload | Optional
|--recurse-submodules | Whether to enumerate files inside of submodules for path-fixing purposes. Off by default. | Optional
|--disable-search | Disable search for coverage files. This is helpful when specifying what files you want to upload with the --file option.| Optional
|-b, --build, --build-code | Specify the build number manually | Optional
|--build-url | The URL of the build where this is running | Optional
Expand Down
8 changes: 8 additions & 0 deletions codecov_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def _turn_env_vars_into_dict(ctx, params, value):
multiple=True,
default=[],
),
click.option(
"--recurse-submodules",
help="Whether to enumerate files inside of submodules for path-fixing purposes. Off by default.",
is_flag=True,
default=False,
),
click.option(
"--disable-search",
help="Disable search for coverage files. This is helpful when specifying what files you want to upload with the --file option.",
Expand Down Expand Up @@ -242,6 +248,7 @@ def do_upload(
network_root_folder: pathlib.Path,
plugin_names: typing.List[str],
pull_request_number: typing.Optional[str],
recurse_submodules: bool,
report_type_str: str,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
Expand Down Expand Up @@ -297,6 +304,7 @@ def do_upload(
network_root_folder=network_root_folder,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
recurse_submodules=recurse_submodules,
report_code=report_code,
slug=slug,
swift_project=swift_project,
Expand Down
3 changes: 3 additions & 0 deletions codecov_cli/commands/upload_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def upload_coverage(
parent_sha: typing.Optional[str],
plugin_names: typing.List[str],
pull_request_number: typing.Optional[str],
recurse_submodules: bool,
report_code: str,
report_type_str: str,
slug: typing.Optional[str],
Expand Down Expand Up @@ -115,6 +116,7 @@ def upload_coverage(
parent_sha=parent_sha,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
recurse_submodules=recurse_submodules,
report_code=report_code,
slug=slug,
swift_project=swift_project,
Expand Down Expand Up @@ -173,6 +175,7 @@ def upload_coverage(
network_root_folder=network_root_folder,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
recurse_submodules=recurse_submodules,
report_code=report_code,
report_type_str=report_type_str,
slug=slug,
Expand Down
2 changes: 2 additions & 0 deletions codecov_cli/commands/upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def upload_process(
parent_sha: typing.Optional[str],
plugin_names: typing.List[str],
pull_request_number: typing.Optional[str],
recurse_submodules: bool,
report_code: str,
report_type_str: str,
slug: typing.Optional[str],
Expand Down Expand Up @@ -122,6 +123,7 @@ def upload_process(
network_root_folder=network_root_folder,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
recurse_submodules=recurse_submodules,
report_code=report_code,
report_type_str=report_type_str,
slug=slug,
Expand Down
17 changes: 11 additions & 6 deletions codecov_cli/helpers/versioning_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_network_root(self) -> t.Optional[Path]:

@abstractmethod
def list_relevant_files(
self, directory: t.Optional[Path] = None
self, directory: t.Optional[Path] = None, recurse_submodules: bool = False
) -> t.Optional[t.List[str]]:
pass

Expand Down Expand Up @@ -125,14 +125,17 @@ def get_network_root(self):
return Path(p.stdout.decode().rstrip())
return None

def list_relevant_files(self, directory: t.Optional[Path] = None) -> t.List[str]:
def list_relevant_files(
self, directory: t.Optional[Path] = None, recurse_submodules: bool = False
) -> t.List[str]:
dir_to_use = directory or self.get_network_root()
if dir_to_use is None:
raise ValueError("Can't determine root folder")

res = subprocess.run(
["git", "-C", str(dir_to_use), "ls-files"], capture_output=True
)
cmd = ["git", "-C", str(dir_to_use), "ls-files"]
if recurse_submodules:
cmd.append("--recurse-submodules")
res = subprocess.run(cmd, capture_output=True)

return [
(
Expand All @@ -155,5 +158,7 @@ def get_network_root(self):
def get_fallback_value(self, fallback_field: FallbackFieldEnum):
return None

def list_relevant_files(self, directory: t.Optional[Path] = None) -> t.List[str]:
def list_relevant_files(
self, directory: t.Optional[Path] = None, recurse_submodules: bool = False
) -> t.List[str]:
return []
2 changes: 2 additions & 0 deletions codecov_cli/services/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def do_upload_logic(
parent_sha: typing.Optional[str] = None,
plugin_names: typing.List[str],
pull_request_number: typing.Optional[str],
recurse_submodules: bool = False,
report_code: str,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
Expand Down Expand Up @@ -87,6 +88,7 @@ def do_upload_logic(
)
network_finder = select_network_finder(
versioning_system,
recurse_submodules=recurse_submodules,
network_filter=network_filter,
network_prefix=network_prefix,
network_root_folder=network_root_folder,
Expand Down
8 changes: 7 additions & 1 deletion codecov_cli/services/upload/network_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ class NetworkFinder(object):
def __init__(
self,
versioning_system: VersioningSystemInterface,
recurse_submodules: bool,
network_filter: typing.Optional[str],
network_prefix: typing.Optional[str],
network_root_folder: pathlib.Path,
):
self.versioning_system = versioning_system
self.recurse_submodules = recurse_submodules
self.network_filter = network_filter
self.network_prefix = network_prefix
self.network_root_folder = network_root_folder

def find_files(self, ignore_filters=False) -> typing.List[str]:
files = self.versioning_system.list_relevant_files(self.network_root_folder)
files = self.versioning_system.list_relevant_files(
self.network_root_folder, self.recurse_submodules
)

if files and not ignore_filters:
if self.network_filter:
Expand All @@ -31,12 +35,14 @@ def find_files(self, ignore_filters=False) -> typing.List[str]:

def select_network_finder(
versioning_system: VersioningSystemInterface,
recurse_submodules: bool,
network_filter: typing.Optional[str],
network_prefix: typing.Optional[str],
network_root_folder: pathlib.Path,
):
return NetworkFinder(
versioning_system,
recurse_submodules,
network_filter,
network_prefix,
network_root_folder,
Expand Down
2 changes: 2 additions & 0 deletions codecov_cli/services/upload_coverage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def upload_coverage_logic(
build_code: typing.Optional[str],
build_url: typing.Optional[str],
commit_sha: str,
recurse_submodules: bool,
disable_file_fixes: bool,
disable_search: bool,
dry_run: bool,
Expand Down Expand Up @@ -58,6 +59,7 @@ def upload_coverage_logic(
build_code=build_code,
build_url=build_url,
commit_sha=commit_sha,
recurse_submodules=recurse_submodules,
disable_file_fixes=disable_file_fixes,
disable_search=disable_search,
dry_run=dry_run,
Expand Down
9 changes: 9 additions & 0 deletions codecovcli_commands
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ Options:
specified files, please consider using
--disable-search to disable uploading other
files.
--recurse-submodules Whether to enumerate files inside of
submodules for path-fixing purposes. Off by
default.
--disable-search Disable search for coverage files. This is
helpful when specifying what files you want
to upload with the --file option.
Expand Down Expand Up @@ -274,6 +277,9 @@ Options:
specified files, please consider using
--disable-search to disable uploading other
files.
--recurse-submodules Whether to enumerate files inside of
submodules for path-fixing purposes. Off by
default.
--disable-search Disable search for coverage files. This is
helpful when specifying what files you want
to upload with the --file option.
Expand Down Expand Up @@ -347,6 +353,9 @@ Options:
specified files, please consider using
--disable-search to disable uploading other
files.
--recurse-submodules Whether to enumerate files inside of
submodules for path-fixing purposes. Off by
default.
--disable-search Disable search for coverage files. This is
helpful when specifying what files you want
to upload with the --file option.
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/test_invoke_upload_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def test_upload_coverage_options(mocker):
" wish to only upload the specified files,",
" please consider using --disable-search to",
" disable uploading other files.",
" --recurse-submodules Whether to enumerate files inside of",
" submodules for path-fixing purposes. Off by",
" default.",
" --disable-search Disable search for coverage files. This is",
" helpful when specifying what files you want to",
" upload with the --file option.",
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/test_invoke_upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def test_upload_process_options(mocker):
" wish to only upload the specified files,",
" please consider using --disable-search to",
" disable uploading other files.",
" --recurse-submodules Whether to enumerate files inside of",
" submodules for path-fixing purposes. Off by",
" default.",
" --disable-search Disable search for coverage files. This is",
" helpful when specifying what files you want to",
" upload with the --file option.",
Expand Down
17 changes: 13 additions & 4 deletions tests/helpers/test_network_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_find_files(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter=None,
network_prefix=None,
network_root_folder=tmp_path,
Expand All @@ -24,6 +25,7 @@ def test_find_files(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter="hello",
network_prefix="bello",
network_root_folder=tmp_path,
Expand All @@ -33,13 +35,14 @@ def test_find_files(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter="hello",
network_prefix="bello",
network_root_folder=tmp_path,
).find_files(True)
== filenames
)
mocked_vs.list_relevant_files.assert_called_with(tmp_path)
mocked_vs.list_relevant_files.assert_called_with(tmp_path, False)


def test_find_files_with_filter(mocker, tmp_path):
Expand All @@ -52,6 +55,7 @@ def test_find_files_with_filter(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter="hello",
network_prefix=None,
network_root_folder=tmp_path,
Expand All @@ -61,13 +65,14 @@ def test_find_files_with_filter(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter="hello",
network_prefix="bello",
network_root_folder=tmp_path,
).find_files(True)
== filenames
)
mocked_vs.list_relevant_files.assert_called_with(tmp_path)
mocked_vs.list_relevant_files.assert_called_with(tmp_path, False)


def test_find_files_with_prefix(mocker, tmp_path):
Expand All @@ -80,6 +85,7 @@ def test_find_files_with_prefix(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter=None,
network_prefix="hello",
network_root_folder=tmp_path,
Expand All @@ -89,13 +95,14 @@ def test_find_files_with_prefix(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter="hello",
network_prefix="bello",
network_root_folder=tmp_path,
).find_files(True)
== filenames
)
mocked_vs.list_relevant_files.assert_called_with(tmp_path)
mocked_vs.list_relevant_files.assert_called_with(tmp_path, False)


def test_find_files_with_filter_and_prefix(mocker, tmp_path):
Expand All @@ -108,6 +115,7 @@ def test_find_files_with_filter_and_prefix(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter="hello",
network_prefix="bello",
network_root_folder=tmp_path,
Expand All @@ -117,10 +125,11 @@ def test_find_files_with_filter_and_prefix(mocker, tmp_path):
assert (
NetworkFinder(
versioning_system=mocked_vs,
recurse_submodules=False,
network_filter="hello",
network_prefix="bello",
network_root_folder=tmp_path,
).find_files(True)
== filenames
)
mocked_vs.list_relevant_files.assert_called_with(tmp_path)
mocked_vs.list_relevant_files.assert_called_with(tmp_path, False)
11 changes: 11 additions & 0 deletions tests/helpers/test_versioning_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ def test_list_relevant_files_fails_if_no_root_is_found(self, mocker):
vs = GitVersioningSystem()
with pytest.raises(ValueError):
vs.list_relevant_files()

def test_list_relevant_files_recurse_submodules(self, mocker, tmp_path):
subproc_run = mocker.patch(
"codecov_cli.helpers.versioning_systems.subprocess.run"
)
vs = GitVersioningSystem()
_ = vs.list_relevant_files(tmp_path, recurse_submodules=True)
subproc_run.assert_called_with(
["git", "-C", str(tmp_path), "ls-files", "--recurse-submodules"],
capture_output=True,
)
4 changes: 2 additions & 2 deletions tests/services/upload/test_upload_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_generate_upload_data(tmp_path):

file_finder = FileFinder(tmp_path)

network_finder = NetworkFinder(GitVersioningSystem(), None, None, None)
network_finder = NetworkFinder(GitVersioningSystem(), False, None, None, None)

collector = UploadCollector([], network_finder, file_finder, None)

Expand All @@ -187,7 +187,7 @@ def test_generate_upload_data_with_none_network(
(tmp_path / "coverage.xml").touch()

file_finder = FileFinder(tmp_path)
network_finder = NetworkFinder(NoVersioningSystem(), None, None, None)
network_finder = NetworkFinder(NoVersioningSystem(), False, None, None, None)

collector = UploadCollector([], network_finder, file_finder, {})

Expand Down
Loading