diff --git a/codecov_cli/commands/upload_coverage.py b/codecov_cli/commands/upload_coverage.py index e071b207..7f22c998 100644 --- a/codecov_cli/commands/upload_coverage.py +++ b/codecov_cli/commands/upload_coverage.py @@ -116,61 +116,60 @@ def upload_coverage( use_legacy_uploader=use_legacy_uploader, args=args, ) - return - - ctx.invoke( - create_commit, - commit_sha=commit_sha, - parent_sha=parent_sha, - pull_request_number=pull_request_number, - branch=branch, - slug=slug, - token=token, - git_service=git_service, - fail_on_error=True, - ) - if report_type == "coverage": + else: ctx.invoke( - create_report, + create_commit, + commit_sha=commit_sha, + parent_sha=parent_sha, + pull_request_number=pull_request_number, + branch=branch, + slug=slug, token=token, - code=report_code, + git_service=git_service, fail_on_error=True, + ) + if report_type == "coverage": + ctx.invoke( + create_report, + token=token, + code=report_code, + fail_on_error=True, + commit_sha=commit_sha, + slug=slug, + git_service=git_service, + ) + ctx.invoke( + do_upload, + branch=branch, + build_code=build_code, + build_url=build_url, commit_sha=commit_sha, - slug=slug, + disable_file_fixes=disable_file_fixes, + disable_search=disable_search, + dry_run=dry_run, + env_vars=env_vars, + fail_on_error=fail_on_error, + files_search_exclude_folders=files_search_exclude_folders, + files_search_explicitly_listed_files=files_search_explicitly_listed_files, + files_search_root_folder=files_search_root_folder, + flags=flags, + gcov_args=gcov_args, + gcov_executable=gcov_executable, + gcov_ignore=gcov_ignore, + gcov_include=gcov_include, git_service=git_service, + handle_no_reports_found=handle_no_reports_found, + job_code=job_code, + name=name, + network_filter=network_filter, + network_prefix=network_prefix, + network_root_folder=network_root_folder, + plugin_names=plugin_names, + pull_request_number=pull_request_number, + report_code=report_code, + report_type=report_type, + slug=slug, + swift_project=swift_project, + token=token, + use_legacy_uploader=use_legacy_uploader, ) - ctx.invoke( - do_upload, - branch=branch, - build_code=build_code, - build_url=build_url, - commit_sha=commit_sha, - disable_file_fixes=disable_file_fixes, - disable_search=disable_search, - dry_run=dry_run, - env_vars=env_vars, - fail_on_error=fail_on_error, - files_search_exclude_folders=files_search_exclude_folders, - files_search_explicitly_listed_files=files_search_explicitly_listed_files, - files_search_root_folder=files_search_root_folder, - flags=flags, - gcov_args=gcov_args, - gcov_executable=gcov_executable, - gcov_ignore=gcov_ignore, - gcov_include=gcov_include, - git_service=git_service, - handle_no_reports_found=handle_no_reports_found, - job_code=job_code, - name=name, - network_filter=network_filter, - network_prefix=network_prefix, - network_root_folder=network_root_folder, - plugin_names=plugin_names, - pull_request_number=pull_request_number, - 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/commands/upload_process.py b/codecov_cli/commands/upload_process.py new file mode 100644 index 00000000..1ee77eca --- /dev/null +++ b/codecov_cli/commands/upload_process.py @@ -0,0 +1,125 @@ +import logging +import pathlib +import typing + +import click + +from codecov_cli.commands.commit import create_commit +from codecov_cli.commands.report import create_report +from codecov_cli.commands.upload import do_upload, global_upload_options +from codecov_cli.helpers.args import get_cli_args +from codecov_cli.helpers.options import global_options +from codecov_cli.types import CommandContext + +logger = logging.getLogger("codecovcli") + + +# These options are the combined options of commit, report and upload commands +@click.command() +@global_options +@global_upload_options +@click.option( + "--parent-sha", + help="SHA (with 40 chars) of what should be the parent of this commit", +) +@click.pass_context +def upload_process( + ctx: CommandContext, + branch: typing.Optional[str], + build_code: typing.Optional[str], + build_url: typing.Optional[str], + commit_sha: str, + disable_file_fixes: bool, + disable_search: bool, + dry_run: bool, + env_vars: typing.Dict[str, str], + fail_on_error: bool, + files_search_exclude_folders: typing.List[pathlib.Path], + files_search_explicitly_listed_files: typing.List[pathlib.Path], + files_search_root_folder: pathlib.Path, + flags: typing.List[str], + gcov_args: typing.Optional[str], + gcov_executable: typing.Optional[str], + gcov_ignore: typing.Optional[str], + gcov_include: typing.Optional[str], + git_service: typing.Optional[str], + handle_no_reports_found: bool, + job_code: typing.Optional[str], + name: typing.Optional[str], + network_filter: typing.Optional[str], + network_prefix: typing.Optional[str], + network_root_folder: pathlib.Path, + parent_sha: typing.Optional[str], + plugin_names: typing.List[str], + pull_request_number: typing.Optional[str], + report_code: str, + report_type: str, + slug: typing.Optional[str], + swift_project: typing.Optional[str], + token: typing.Optional[str], + use_legacy_uploader: bool, +): + args = get_cli_args(ctx) + logger.debug( + "Starting upload process", + extra=dict( + extra_log_attributes=args, + ), + ) + + ctx.invoke( + create_commit, + commit_sha=commit_sha, + parent_sha=parent_sha, + pull_request_number=pull_request_number, + branch=branch, + slug=slug, + token=token, + git_service=git_service, + fail_on_error=True, + ) + if report_type == "coverage": + ctx.invoke( + create_report, + token=token, + code=report_code, + fail_on_error=True, + commit_sha=commit_sha, + slug=slug, + git_service=git_service, + ) + ctx.invoke( + do_upload, + branch=branch, + build_code=build_code, + build_url=build_url, + commit_sha=commit_sha, + disable_file_fixes=disable_file_fixes, + disable_search=disable_search, + dry_run=dry_run, + env_vars=env_vars, + fail_on_error=fail_on_error, + files_search_exclude_folders=files_search_exclude_folders, + files_search_explicitly_listed_files=files_search_explicitly_listed_files, + files_search_root_folder=files_search_root_folder, + flags=flags, + gcov_args=gcov_args, + gcov_executable=gcov_executable, + gcov_ignore=gcov_ignore, + gcov_include=gcov_include, + git_service=git_service, + handle_no_reports_found=handle_no_reports_found, + job_code=job_code, + name=name, + network_filter=network_filter, + network_prefix=network_prefix, + network_root_folder=network_root_folder, + plugin_names=plugin_names, + pull_request_number=pull_request_number, + 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/main.py b/codecov_cli/main.py index d1c8cd97..0640fad8 100644 --- a/codecov_cli/main.py +++ b/codecov_cli/main.py @@ -17,6 +17,7 @@ from codecov_cli.commands.staticanalysis import static_analysis from codecov_cli.commands.upload import do_upload from codecov_cli.commands.upload_coverage import upload_coverage +from codecov_cli.commands.upload_process import upload_process from codecov_cli.helpers.ci_adapters import get_ci_adapter, get_ci_providers_list from codecov_cli.helpers.config import load_cli_config from codecov_cli.helpers.logging_utils import configure_logger @@ -75,6 +76,7 @@ def cli( cli.add_command(static_analysis) cli.add_command(empty_upload) cli.add_command(upload_coverage) +cli.add_command(upload_process) cli.add_command(send_notifications) cli.add_command(process_test_results) diff --git a/tests/commands/test_invoke_upload_coverage.py b/tests/commands/test_invoke_upload_coverage.py index 3558ed06..47f7e124 100644 --- a/tests/commands/test_invoke_upload_coverage.py +++ b/tests/commands/test_invoke_upload_coverage.py @@ -8,7 +8,7 @@ from tests.factory import FakeProvider, FakeVersioningSystem -def test_upload_coverage_missing_commit_sha(mocker): +def test_upload_process_missing_commit_sha(mocker): fake_ci_provider = FakeProvider({FallbackFieldEnum.commit_sha: None}) fake_versioning_system = FakeVersioningSystem({FallbackFieldEnum.commit_sha: None}) mocker.patch( @@ -17,11 +17,11 @@ def test_upload_coverage_missing_commit_sha(mocker): mocker.patch("codecov_cli.main.get_ci_adapter", return_value=fake_ci_provider) runner = CliRunner() with runner.isolated_filesystem(): - result = runner.invoke(cli, ["upload-coverage"], obj={}) + result = runner.invoke(cli, ["upload-process"], obj={}) assert result.exit_code != 0 -def test_upload_coverage_raise_Z_option(mocker, use_verbose_option): +def test_upload_process_raise_Z_option(mocker, use_verbose_option): error = RequestError( code=401, params={"some": "params"}, description="Unauthorized" ) @@ -38,7 +38,7 @@ def test_upload_coverage_raise_Z_option(mocker, use_verbose_option): result = runner.invoke( cli, [ - "upload-coverage", + "upload-process", "--fail-on-error", "-C", "command-sha", @@ -55,18 +55,18 @@ def test_upload_coverage_raise_Z_option(mocker, use_verbose_option): assert str(result) == "" -def test_upload_coverage_options(mocker): +def test_upload_process_options(mocker): runner = CliRunner() fake_ci_provider = FakeProvider({FallbackFieldEnum.commit_sha: None}) mocker.patch("codecov_cli.main.get_ci_adapter", return_value=fake_ci_provider) with runner.isolated_filesystem(): runner = CliRunner() - result = runner.invoke(cli, ["upload-coverage", "-h"], obj={}) + result = runner.invoke(cli, ["upload-process", "-h"], obj={}) assert result.exit_code == 0 print(result.output) assert result.output.split("\n")[1:] == [ - "Usage: cli upload-coverage [OPTIONS]", + "Usage: cli upload-process [OPTIONS]", "", "Options:", " -C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required]", diff --git a/tests/test_codecov_cli.py b/tests/test_codecov_cli.py index de66aa60..6d3a81c3 100644 --- a/tests/test_codecov_cli.py +++ b/tests/test_codecov_cli.py @@ -15,4 +15,5 @@ def test_existing_commands(): "send-notifications", "static-analysis", "upload-coverage", + "upload-process", ]