|
| 1 | +import logging |
| 2 | +import pathlib |
| 3 | +import typing |
| 4 | + |
| 5 | +import click |
| 6 | + |
| 7 | +from codecov_cli.commands.commit import create_commit |
| 8 | +from codecov_cli.commands.report import create_report |
| 9 | +from codecov_cli.commands.upload import do_upload, global_upload_options |
| 10 | +from codecov_cli.helpers.args import get_cli_args |
| 11 | +from codecov_cli.helpers.options import global_options |
| 12 | +from codecov_cli.services.upload_coverage import upload_coverage_logic |
| 13 | +from codecov_cli.types import CommandContext |
| 14 | + |
| 15 | +logger = logging.getLogger("codecovcli") |
| 16 | + |
| 17 | + |
| 18 | +# These options are the combined options of commit, report and upload commands |
| 19 | +@click.command() |
| 20 | +@global_options |
| 21 | +@global_upload_options |
| 22 | +@click.option( |
| 23 | + "--parent-sha", |
| 24 | + help="SHA (with 40 chars) of what should be the parent of this commit", |
| 25 | +) |
| 26 | +@click.pass_context |
| 27 | +def upload_coverage( |
| 28 | + ctx: CommandContext, |
| 29 | + branch: typing.Optional[str], |
| 30 | + build_code: typing.Optional[str], |
| 31 | + build_url: typing.Optional[str], |
| 32 | + commit_sha: str, |
| 33 | + disable_file_fixes: bool, |
| 34 | + disable_search: bool, |
| 35 | + dry_run: bool, |
| 36 | + env_vars: typing.Dict[str, str], |
| 37 | + fail_on_error: bool, |
| 38 | + files_search_exclude_folders: typing.List[pathlib.Path], |
| 39 | + files_search_explicitly_listed_files: typing.List[pathlib.Path], |
| 40 | + files_search_root_folder: pathlib.Path, |
| 41 | + flags: typing.List[str], |
| 42 | + gcov_args: typing.Optional[str], |
| 43 | + gcov_executable: typing.Optional[str], |
| 44 | + gcov_ignore: typing.Optional[str], |
| 45 | + gcov_include: typing.Optional[str], |
| 46 | + git_service: typing.Optional[str], |
| 47 | + handle_no_reports_found: bool, |
| 48 | + job_code: typing.Optional[str], |
| 49 | + name: typing.Optional[str], |
| 50 | + network_filter: typing.Optional[str], |
| 51 | + network_prefix: typing.Optional[str], |
| 52 | + network_root_folder: pathlib.Path, |
| 53 | + parent_sha: typing.Optional[str], |
| 54 | + plugin_names: typing.List[str], |
| 55 | + pull_request_number: typing.Optional[str], |
| 56 | + report_code: str, |
| 57 | + report_type: str, |
| 58 | + slug: typing.Optional[str], |
| 59 | + swift_project: typing.Optional[str], |
| 60 | + token: typing.Optional[str], |
| 61 | + use_legacy_uploader: bool, |
| 62 | +): |
| 63 | + args = get_cli_args(ctx) |
| 64 | + logger.debug( |
| 65 | + "Starting upload coverage", |
| 66 | + extra=dict( |
| 67 | + extra_log_attributes=args, |
| 68 | + ), |
| 69 | + ) |
| 70 | + |
| 71 | + if not use_legacy_uploader and report_type == "coverage": |
| 72 | + versioning_system = ctx.obj["versioning_system"] |
| 73 | + codecov_yaml = ctx.obj["codecov_yaml"] or {} |
| 74 | + cli_config = codecov_yaml.get("cli", {}) |
| 75 | + ci_adapter = ctx.obj.get("ci_adapter") |
| 76 | + enterprise_url = ctx.obj.get("enterprise_url") |
| 77 | + args = get_cli_args(ctx) |
| 78 | + ctx.invoke( |
| 79 | + upload_coverage_logic, |
| 80 | + cli_config, |
| 81 | + versioning_system, |
| 82 | + ci_adapter, |
| 83 | + branch=branch, |
| 84 | + build_code=build_code, |
| 85 | + build_url=build_url, |
| 86 | + commit_sha=commit_sha, |
| 87 | + disable_file_fixes=disable_file_fixes, |
| 88 | + disable_search=disable_search, |
| 89 | + dry_run=dry_run, |
| 90 | + enterprise_url=enterprise_url, |
| 91 | + env_vars=env_vars, |
| 92 | + fail_on_error=fail_on_error, |
| 93 | + files_search_exclude_folders=files_search_exclude_folders, |
| 94 | + files_search_explicitly_listed_files=files_search_explicitly_listed_files, |
| 95 | + files_search_root_folder=files_search_root_folder, |
| 96 | + flags=flags, |
| 97 | + gcov_args=gcov_args, |
| 98 | + gcov_executable=gcov_executable, |
| 99 | + gcov_ignore=gcov_ignore, |
| 100 | + gcov_include=gcov_include, |
| 101 | + git_service=git_service, |
| 102 | + handle_no_reports_found=handle_no_reports_found, |
| 103 | + job_code=job_code, |
| 104 | + name=name, |
| 105 | + network_filter=network_filter, |
| 106 | + network_prefix=network_prefix, |
| 107 | + network_root_folder=network_root_folder, |
| 108 | + parent_sha=parent_sha, |
| 109 | + plugin_names=plugin_names, |
| 110 | + pull_request_number=pull_request_number, |
| 111 | + report_code=report_code, |
| 112 | + slug=slug, |
| 113 | + swift_project=swift_project, |
| 114 | + token=token, |
| 115 | + upload_file_type=report_type, |
| 116 | + use_legacy_uploader=use_legacy_uploader, |
| 117 | + args=args, |
| 118 | + ) |
| 119 | + else: |
| 120 | + ctx.invoke( |
| 121 | + create_commit, |
| 122 | + commit_sha=commit_sha, |
| 123 | + parent_sha=parent_sha, |
| 124 | + pull_request_number=pull_request_number, |
| 125 | + branch=branch, |
| 126 | + slug=slug, |
| 127 | + token=token, |
| 128 | + git_service=git_service, |
| 129 | + fail_on_error=True, |
| 130 | + ) |
| 131 | + if report_type == "coverage": |
| 132 | + ctx.invoke( |
| 133 | + create_report, |
| 134 | + token=token, |
| 135 | + code=report_code, |
| 136 | + fail_on_error=True, |
| 137 | + commit_sha=commit_sha, |
| 138 | + slug=slug, |
| 139 | + git_service=git_service, |
| 140 | + ) |
| 141 | + ctx.invoke( |
| 142 | + do_upload, |
| 143 | + branch=branch, |
| 144 | + build_code=build_code, |
| 145 | + build_url=build_url, |
| 146 | + commit_sha=commit_sha, |
| 147 | + disable_file_fixes=disable_file_fixes, |
| 148 | + disable_search=disable_search, |
| 149 | + dry_run=dry_run, |
| 150 | + env_vars=env_vars, |
| 151 | + fail_on_error=fail_on_error, |
| 152 | + files_search_exclude_folders=files_search_exclude_folders, |
| 153 | + files_search_explicitly_listed_files=files_search_explicitly_listed_files, |
| 154 | + files_search_root_folder=files_search_root_folder, |
| 155 | + flags=flags, |
| 156 | + gcov_args=gcov_args, |
| 157 | + gcov_executable=gcov_executable, |
| 158 | + gcov_ignore=gcov_ignore, |
| 159 | + gcov_include=gcov_include, |
| 160 | + git_service=git_service, |
| 161 | + handle_no_reports_found=handle_no_reports_found, |
| 162 | + job_code=job_code, |
| 163 | + name=name, |
| 164 | + network_filter=network_filter, |
| 165 | + network_prefix=network_prefix, |
| 166 | + network_root_folder=network_root_folder, |
| 167 | + plugin_names=plugin_names, |
| 168 | + pull_request_number=pull_request_number, |
| 169 | + report_code=report_code, |
| 170 | + report_type=report_type, |
| 171 | + slug=slug, |
| 172 | + swift_project=swift_project, |
| 173 | + token=token, |
| 174 | + use_legacy_uploader=use_legacy_uploader, |
| 175 | + ) |
0 commit comments