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

Upload-process uses combined-upload endpoint #551

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.services.upload_coverage import upload_coverage_logic
from codecov_cli.types import CommandContext

logger = logging.getLogger("codecovcli")
Expand All @@ -23,7 +24,7 @@
help="SHA (with 40 chars) of what should be the parent of this commit",
)
@click.pass_context
def upload_process(
def upload_coverage(
ctx: CommandContext,
branch: typing.Optional[str],
build_code: typing.Optional[str],
Expand Down Expand Up @@ -61,12 +62,62 @@ def upload_process(
):
args = get_cli_args(ctx)
logger.debug(
"Starting upload process",
"Starting upload coverage",
extra=dict(
extra_log_attributes=args,
),
)

if not use_legacy_uploader and report_type == "coverage":
versioning_system = ctx.obj["versioning_system"]
codecov_yaml = ctx.obj["codecov_yaml"] or {}
cli_config = codecov_yaml.get("cli", {})
ci_adapter = ctx.obj.get("ci_adapter")
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
ctx.invoke(
upload_coverage_logic,
cli_config,
versioning_system,
ci_adapter,
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,
enterprise_url=enterprise_url,
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,
parent_sha=parent_sha,
plugin_names=plugin_names,
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,
args=args,
)
return

ctx.invoke(
create_commit,
commit_sha=commit_sha,
Expand Down
4 changes: 2 additions & 2 deletions codecov_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from codecov_cli.commands.send_notifications import send_notifications
from codecov_cli.commands.staticanalysis import static_analysis
from codecov_cli.commands.upload import do_upload
from codecov_cli.commands.upload_process import upload_process
from codecov_cli.commands.upload_coverage import upload_coverage
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
Expand Down Expand Up @@ -74,7 +74,7 @@ def cli(
cli.add_command(label_analysis)
cli.add_command(static_analysis)
cli.add_command(empty_upload)
cli.add_command(upload_process)
cli.add_command(upload_coverage)
cli.add_command(send_notifications)
cli.add_command(process_test_results)

Expand Down
4 changes: 4 additions & 0 deletions codecov_cli/services/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def do_upload_logic(
cli_config: typing.Dict,
versioning_system: VersioningSystemInterface,
ci_adapter: CIAdapterBase,
upload_coverage: bool = False,
*,
args: dict = None,
branch: typing.Optional[str],
Expand Down Expand Up @@ -51,6 +52,7 @@ def do_upload_logic(
network_filter: typing.Optional[str],
network_prefix: typing.Optional[str],
network_root_folder: Path,
parent_sha: typing.Optional[str] = None,
plugin_names: typing.List[str],
pull_request_number: typing.Optional[str],
report_code: str,
Expand Down Expand Up @@ -148,6 +150,8 @@ def do_upload_logic(
ci_service,
git_service,
enterprise_url,
parent_sha,
upload_coverage,
args,
)
else:
Expand Down
16 changes: 15 additions & 1 deletion codecov_cli/services/upload/upload_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def send_upload_data(
ci_service: typing.Optional[str] = None,
git_service: typing.Optional[str] = None,
enterprise_url: typing.Optional[str] = None,
parent_sha: typing.Optional[str] = None,
upload_coverage: bool = False,
args: dict = None,
) -> RequestResult:
data = {
Expand All @@ -54,6 +56,12 @@ def send_upload_data(
"name": name,
"version": codecov_cli_version,
}
if upload_coverage:
data["branch"] = branch
data["code"] = report_code
data["commit_sha"] = commit_sha
data["parent_commit_id"] = parent_sha
data["pullid"] = pull_request_number
headers = get_token_header(token)
encoded_slug = encode_slug(slug)
upload_url = enterprise_url or CODECOV_INGEST_URL
Expand All @@ -66,6 +74,7 @@ def send_upload_data(
encoded_slug,
commit_sha,
report_code,
upload_coverage,
)
# Data that goes to storage
reports_payload = self._generate_payload(
Expand Down Expand Up @@ -176,9 +185,14 @@ def get_url_and_possibly_update_data(
encoded_slug,
commit_sha,
report_code,
upload_coverage=False,
):
if report_type == "coverage":
url = f"{upload_url}/upload/{git_service}/{encoded_slug}/commits/{commit_sha}/reports/{report_code}/uploads"
base_url = f"{upload_url}/upload/{git_service}/{encoded_slug}"
if upload_coverage:
url = f"{base_url}/upload-coverage"
else:
url = f"{base_url}/commits/{commit_sha}/reports/{report_code}/uploads"
elif report_type == "test_results":
data["slug"] = encoded_slug
data["branch"] = branch
Expand Down
90 changes: 90 additions & 0 deletions codecov_cli/services/upload_coverage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import pathlib
import typing

from codecov_cli.helpers.ci_adapters.base import CIAdapterBase
from codecov_cli.helpers.versioning_systems import VersioningSystemInterface
from codecov_cli.services.upload import do_upload_logic


def upload_coverage_logic(
cli_config: typing.Dict,
versioning_system: VersioningSystemInterface,
ci_adapter: CIAdapterBase,
*,
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,
enterprise_url: typing.Optional[str],
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,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
token: typing.Optional[str],
use_legacy_uploader: bool,
upload_file_type: str = "coverage",
args: dict = None,
):
return do_upload_logic(
cli_config=cli_config,
versioning_system=versioning_system,
ci_adapter=ci_adapter,
upload_coverage=True,
args=args,
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,
enterprise_url=enterprise_url,
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,
parent_sha=parent_sha,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
report_code=report_code,
slug=slug,
swift_project=swift_project,
token=token,
use_legacy_uploader=use_legacy_uploader,
upload_file_type=upload_file_type,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tests.factory import FakeProvider, FakeVersioningSystem


def test_upload_process_missing_commit_sha(mocker):
def test_upload_coverage_missing_commit_sha(mocker):
fake_ci_provider = FakeProvider({FallbackFieldEnum.commit_sha: None})
fake_versioning_system = FakeVersioningSystem({FallbackFieldEnum.commit_sha: None})
mocker.patch(
Expand All @@ -17,11 +17,11 @@ def test_upload_process_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-process"], obj={})
result = runner.invoke(cli, ["upload-coverage"], obj={})
assert result.exit_code != 0


def test_upload_process_raise_Z_option(mocker, use_verbose_option):
def test_upload_coverage_raise_Z_option(mocker, use_verbose_option):
error = RequestError(
code=401, params={"some": "params"}, description="Unauthorized"
)
Expand All @@ -38,12 +38,14 @@ def test_upload_process_raise_Z_option(mocker, use_verbose_option):
result = runner.invoke(
cli,
[
"upload-process",
"upload-coverage",
"--fail-on-error",
"-C",
"command-sha",
"--slug",
"owner/repo",
"--report-type",
"test_results",
],
obj={},
)
Expand All @@ -53,18 +55,18 @@ def test_upload_process_raise_Z_option(mocker, use_verbose_option):
assert str(result) == "<Result SystemExit(1)>"


def test_upload_process_options(mocker):
def test_upload_coverage_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-process", "-h"], obj={})
result = runner.invoke(cli, ["upload-coverage", "-h"], obj={})
assert result.exit_code == 0
print(result.output)

assert result.output.split("\n")[1:] == [
"Usage: cli upload-process [OPTIONS]",
"Usage: cli upload-coverage [OPTIONS]",
"",
"Options:",
" -C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required]",
Expand Down
6 changes: 6 additions & 0 deletions tests/services/upload/test_upload_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker):
"git_service",
None,
None,
False,
None,
)


Expand Down Expand Up @@ -235,6 +237,8 @@ def test_do_upload_logic_happy_path(mocker):
"git_service",
None,
None,
False,
None,
)


Expand Down Expand Up @@ -684,5 +688,7 @@ def test_do_upload_logic_happy_path_test_results(mocker):
"service",
"git_service",
None,
None,
False,
{"args": "fake_args"},
)
2 changes: 1 addition & 1 deletion tests/test_codecov_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def test_existing_commands():
"process-test-results",
"send-notifications",
"static-analysis",
"upload-process",
"upload-coverage",
]
Loading