Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable file fixes #276

Merged
merged 1 commit into from
Oct 5, 2023
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
9 changes: 9 additions & 0 deletions codecov_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def _turn_env_vars_into_dict(ctx, params, value):
is_flag=True,
default=False,
),
click.option(
"--disable-file-fixes",
help="Disable file fixes to ignore common lines from coverage (e.g. blank lines or empty brackets)",
is_flag=True,
default=False,
),
click.option(
"-b",
"--build",
Expand Down Expand Up @@ -178,6 +184,7 @@ def do_upload(
coverage_files_search_exclude_folders: typing.List[pathlib.Path],
coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path],
disable_search: bool,
disable_file_fixes: bool,
token: typing.Optional[uuid.UUID],
plugin_names: typing.List[str],
branch: typing.Optional[str],
Expand Down Expand Up @@ -218,6 +225,7 @@ def do_upload(
git_service=git_service,
enterprise_url=enterprise_url,
disable_search=disable_search,
disable_file_fixes=disable_file_fixes,
handle_no_reports_found=handle_no_reports_found,
)
),
Expand Down Expand Up @@ -254,4 +262,5 @@ def do_upload(
enterprise_url=enterprise_url,
disable_search=disable_search,
handle_no_reports_found=handle_no_reports_found,
disable_file_fixes=disable_file_fixes,
)
3 changes: 3 additions & 0 deletions codecov_cli/commands/upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def upload_process(
coverage_files_search_exclude_folders: typing.List[pathlib.Path],
coverage_files_search_explicitly_listed_files: typing.List[pathlib.Path],
disable_search: bool,
disable_file_fixes: bool,
token: typing.Optional[uuid.UUID],
plugin_names: typing.List[str],
branch: typing.Optional[str],
Expand Down Expand Up @@ -72,6 +73,7 @@ def upload_process(
pull_request_number=pull_request_number,
git_service=git_service,
disable_search=disable_search,
disable_file_fixes=disable_file_fixes,
fail_on_error=fail_on_error,
handle_no_reports_found=handle_no_reports_found,
)
Expand Down Expand Up @@ -123,4 +125,5 @@ def upload_process(
dry_run=dry_run,
git_service=git_service,
handle_no_reports_found=handle_no_reports_found,
disable_file_fixes=disable_file_fixes,
)
3 changes: 2 additions & 1 deletion codecov_cli/services/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def do_upload_logic(
enterprise_url: typing.Optional[str],
disable_search: bool = False,
handle_no_reports_found: bool = False,
disable_file_fixes: bool = False,
):
preparation_plugins = select_preparation_plugins(cli_config, plugin_names)
coverage_file_selector = select_coverage_file_finder(
Expand All @@ -60,7 +61,7 @@ def do_upload_logic(
)
network_finder = select_network_finder(versioning_system)
collector = UploadCollector(
preparation_plugins, network_finder, coverage_file_selector
preparation_plugins, network_finder, coverage_file_selector, disable_file_fixes
)
try:
upload_data = collector.generate_upload_data()
Expand Down
4 changes: 3 additions & 1 deletion codecov_cli/services/upload/upload_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ def __init__(
preparation_plugins: typing.List[PreparationPluginInterface],
network_finder: NetworkFinder,
coverage_file_finder: CoverageFileFinder,
disable_file_fixes: bool = False,
):
self.preparation_plugins = preparation_plugins
self.network_finder = network_finder
self.coverage_file_finder = coverage_file_finder
self.disable_file_fixes = disable_file_fixes

def _produce_file_fixes_for_network(
self, network: typing.List[str]
) -> typing.List[UploadCollectionResultFileFixer]:
if not network:
if not network or self.disable_file_fixes:
return []
# patterns that we don't need to specify a reason for
empty_line_regex = re.compile(r"^\s*$")
Expand Down
2 changes: 2 additions & 0 deletions tests/commands/test_invoke_upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def test_upload_process_options(mocker):
" --disable-search Disable search for coverage files. This is",
" helpful when specifying what files you want to",
" uload with the --file option.",
" --disable-file-fixes Disable file fixes to ignore common lines from",
" coverage (e.g. blank lines or empty brackets)",
" -b, --build, --build-code TEXT Specify the build number manually",
" --build-url TEXT The URL of the build where this is running",
" --job-code TEXT",
Expand Down
11 changes: 11 additions & 0 deletions tests/services/upload/test_upload_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,14 @@ def test_fix_for_cpp_swift_vala(tmp_path):
(7, "// LCOV_EXCL_START\n"),
]
)


def test_fix_when_disabled_fixes(tmp_path):
cpp_file = Path("tests/data/files_to_fix_examples/sample.cpp")

col = UploadCollector(None, None, None, True)

fixes = col._produce_file_fixes_for_network([str(cpp_file)])

assert len(fixes) == 0
assert fixes == []