diff --git a/codecov_cli/commands/upload.py b/codecov_cli/commands/upload.py index e191fae0..2b78f687 100644 --- a/codecov_cli/commands/upload.py +++ b/codecov_cli/commands/upload.py @@ -194,6 +194,10 @@ def _turn_env_vars_into_dict(ctx, params, value): "--gcov-executable", help="gcov executable to run. Defaults to 'gcov'", ), + click.option( + "--swift-project", + help="Specify the swift project", + ), ] @@ -238,6 +242,7 @@ def do_upload( pull_request_number: typing.Optional[str], report_type: str, slug: typing.Optional[str], + swift_project: typing.Optional[str], token: typing.Optional[str], use_legacy_uploader: bool, ): @@ -286,6 +291,7 @@ def do_upload( pull_request_number=pull_request_number, report_code=report_code, slug=slug, + swift_project=swift_project, token=token, upload_file_type=report_type, use_legacy_uploader=use_legacy_uploader, diff --git a/codecov_cli/commands/upload_process.py b/codecov_cli/commands/upload_process.py index b30cdb27..1ee77eca 100644 --- a/codecov_cli/commands/upload_process.py +++ b/codecov_cli/commands/upload_process.py @@ -55,6 +55,7 @@ def upload_process( report_code: str, report_type: str, slug: typing.Optional[str], + swift_project: typing.Optional[str], token: typing.Optional[str], use_legacy_uploader: bool, ): @@ -118,6 +119,7 @@ def upload_process( report_code=report_code, report_type=report_type, slug=slug, + swift_project=swift_project, token=token, use_legacy_uploader=use_legacy_uploader, ) diff --git a/codecov_cli/plugins/__init__.py b/codecov_cli/plugins/__init__.py index df17c8ab..db7a8a4d 100644 --- a/codecov_cli/plugins/__init__.py +++ b/codecov_cli/plugins/__init__.py @@ -80,7 +80,9 @@ def _get_plugin(cli_config, plugin_name, plugin_config): config = cli_config.get("plugins", {}).get("pycoverage", {}) return Pycoverage(config) if plugin_name == "xcode": - return XcodePlugin() + return XcodePlugin( + plugin_config.get("swift_project", None), + ) if plugin_name == "compress-pycoverage": config = cli_config.get("plugins", {}).get("compress-pycoverage", {}) return CompressPycoverageContexts(config) diff --git a/codecov_cli/plugins/xcode.py b/codecov_cli/plugins/xcode.py index a0dae751..d8e4d0db 100644 --- a/codecov_cli/plugins/xcode.py +++ b/codecov_cli/plugins/xcode.py @@ -16,12 +16,13 @@ class XcodePlugin(object): def __init__( self, + app_name: typing.Optional[str] = None, derived_data_folder: typing.Optional[pathlib.Path] = None, - app_name: typing.Optional[pathlib.Path] = None, ): - self.derived_data_folder = pathlib.Path( - derived_data_folder or "~/Library/Developer/Xcode/DerivedData" - ).expanduser() + self.derived_data_folder = ( + derived_data_folder + or pathlib.Path("~/Library/Developer/Xcode/DerivedData").expanduser() + ) # this is to speed up processing and to build reports for the project being tested, # if empty the plugin will build reports for every xcode project it finds diff --git a/codecov_cli/services/upload/__init__.py b/codecov_cli/services/upload/__init__.py index c9f2b779..ae1a22a2 100644 --- a/codecov_cli/services/upload/__init__.py +++ b/codecov_cli/services/upload/__init__.py @@ -55,6 +55,7 @@ def do_upload_logic( pull_request_number: typing.Optional[str], report_code: str, slug: typing.Optional[str], + swift_project: typing.Optional[str], token: str, upload_file_type: str = "coverage", use_legacy_uploader: bool = False, @@ -66,6 +67,7 @@ def do_upload_logic( "gcov_ignore": gcov_ignore, "gcov_include": gcov_include, "project_root": files_search_root_folder, + "swift_project": swift_project, } if upload_file_type == "coverage": preparation_plugins = select_preparation_plugins( diff --git a/tests/commands/test_invoke_upload_process.py b/tests/commands/test_invoke_upload_process.py index 8f6fcbdc..59f70851 100644 --- a/tests/commands/test_invoke_upload_process.py +++ b/tests/commands/test_invoke_upload_process.py @@ -130,6 +130,7 @@ def test_upload_process_options(mocker): " --gcov-ignore TEXT Paths to ignore during gcov gathering", " --gcov-include TEXT Paths to include during gcov gathering", " --gcov-executable TEXT gcov executable to run. Defaults to 'gcov'", + " --swift-project TEXT Specify the swift project", " --parent-sha TEXT SHA (with 40 chars) of what should be the", " parent of this commit", " -h, --help Show this message and exit.", diff --git a/tests/services/upload/test_upload_service.py b/tests/services/upload/test_upload_service.py index b6beca3f..7c33aba2 100644 --- a/tests/services/upload/test_upload_service.py +++ b/tests/services/upload/test_upload_service.py @@ -71,6 +71,7 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker): branch="branch", use_legacy_uploader=True, slug="slug", + swift_project="App", pull_request_number="pr", git_service="git_service", enterprise_url=None, @@ -85,7 +86,7 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker): assert res == LegacyUploadSender.send_upload_data.return_value mock_select_preparation_plugins.assert_called_with( - cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None} + cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'} ) mock_select_file_finder.assert_called_with(None, None, None, False, "coverage") mock_select_network_finder.assert_called_with( @@ -171,6 +172,7 @@ def test_do_upload_logic_happy_path(mocker): token="token", branch="branch", slug="slug", + swift_project="App", pull_request_number="pr", git_service="git_service", enterprise_url=None, @@ -184,7 +186,7 @@ def test_do_upload_logic_happy_path(mocker): assert res == UploadSender.send_upload_data.return_value mock_select_preparation_plugins.assert_called_with( - cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None} + cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'} ) mock_select_file_finder.assert_called_with(None, None, None, False, "coverage") mock_select_network_finder.assert_called_with( @@ -266,6 +268,7 @@ def test_do_upload_logic_dry_run(mocker): token="token", branch="branch", slug="slug", + swift_project="App", pull_request_number="pr", dry_run=True, git_service="git_service", @@ -282,7 +285,7 @@ def test_do_upload_logic_dry_run(mocker): assert mock_generate_upload_data.call_count == 1 assert mock_send_upload_data.call_count == 0 mock_select_preparation_plugins.assert_called_with( - cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None} + cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'} ) assert out_bytes == [ ("info", "dry-run option activated. NOT sending data to Codecov."), @@ -340,6 +343,7 @@ def test_do_upload_logic_verbose(mocker, use_verbose_option): pull_request_number="pr", report_code="report_code", slug="slug", + swift_project="App", token="token", upload_file_type="coverage", use_legacy_uploader=True, @@ -419,6 +423,7 @@ def side_effect(*args, **kwargs): token="token", branch="branch", slug="slug", + swift_project="App", pull_request_number="pr", git_service="git_service", enterprise_url=None, @@ -438,7 +443,7 @@ def side_effect(*args, **kwargs): text="No coverage reports found. Triggering notificaions without uploading.", ) mock_select_preparation_plugins.assert_called_with( - cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None} + cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'} ) mock_select_file_finder.assert_called_with(None, None, None, False, "coverage") mock_select_network_finder.assert_called_with( @@ -511,6 +516,7 @@ def side_effect(*args, **kwargs): token="token", branch="branch", slug="slug", + swift_project="App", pull_request_number="pr", git_service="git_service", enterprise_url=None, @@ -521,7 +527,7 @@ def side_effect(*args, **kwargs): == "No coverage reports found. Please make sure you're generating reports successfully." ) mock_select_preparation_plugins.assert_called_with( - cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None} + cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'} ) mock_select_file_finder.assert_called_with(None, None, None, False, "coverage") mock_select_network_finder.assert_called_with( @@ -564,33 +570,34 @@ def test_do_upload_logic_happy_path_test_results(mocker): cli_config, versioning_system, ci_adapter, - upload_file_type="test_results", - commit_sha="commit_sha", - report_code="report_code", + args={"args": "fake_args"}, + branch="branch", build_code="build_code", build_url="build_url", - job_code="job_code", + commit_sha="commit_sha", + enterprise_url=None, env_vars=None, + files_search_exclude_folders=None, + files_search_explicitly_listed_files=None, + files_search_root_folder=None, flags=None, gcov_args=None, gcov_executable=None, gcov_ignore=None, gcov_include=None, + git_service="git_service", + job_code="job_code", name="name", network_filter="some_dir", network_prefix="hello/", network_root_folder="root/", - files_search_root_folder=None, - files_search_exclude_folders=None, - files_search_explicitly_listed_files=None, plugin_names=["first_plugin", "another", "forth"], - token="token", - branch="branch", - slug="slug", pull_request_number="pr", - git_service="git_service", - enterprise_url=None, - args={"args": "fake_args"}, + report_code="report_code", + slug="slug", + swift_project="App", + token="token", + upload_file_type="test_results", ) out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue()) assert out_bytes == [