Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 1f04560

Browse files
authored
Adds upload-coverage command (#551)
* Adds single endpoint coverage command "upload-coverage"
1 parent 0ebc513 commit 1f04560

File tree

10 files changed

+476
-1
lines changed

10 files changed

+476
-1
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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+
)

codecov_cli/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from codecov_cli.commands.send_notifications import send_notifications
1717
from codecov_cli.commands.staticanalysis import static_analysis
1818
from codecov_cli.commands.upload import do_upload
19+
from codecov_cli.commands.upload_coverage import upload_coverage
1920
from codecov_cli.commands.upload_process import upload_process
2021
from codecov_cli.helpers.ci_adapters import get_ci_adapter, get_ci_providers_list
2122
from codecov_cli.helpers.config import load_cli_config
@@ -74,6 +75,7 @@ def cli(
7475
cli.add_command(label_analysis)
7576
cli.add_command(static_analysis)
7677
cli.add_command(empty_upload)
78+
cli.add_command(upload_coverage)
7779
cli.add_command(upload_process)
7880
cli.add_command(send_notifications)
7981
cli.add_command(process_test_results)

codecov_cli/services/upload/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def do_upload_logic(
2424
cli_config: typing.Dict,
2525
versioning_system: VersioningSystemInterface,
2626
ci_adapter: CIAdapterBase,
27+
upload_coverage: bool = False,
2728
*,
2829
args: dict = None,
2930
branch: typing.Optional[str],
@@ -51,6 +52,7 @@ def do_upload_logic(
5152
network_filter: typing.Optional[str],
5253
network_prefix: typing.Optional[str],
5354
network_root_folder: Path,
55+
parent_sha: typing.Optional[str] = None,
5456
plugin_names: typing.List[str],
5557
pull_request_number: typing.Optional[str],
5658
report_code: str,
@@ -148,6 +150,8 @@ def do_upload_logic(
148150
ci_service,
149151
git_service,
150152
enterprise_url,
153+
parent_sha,
154+
upload_coverage,
151155
args,
152156
)
153157
else:

codecov_cli/services/upload/upload_sender.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def send_upload_data(
4242
ci_service: typing.Optional[str] = None,
4343
git_service: typing.Optional[str] = None,
4444
enterprise_url: typing.Optional[str] = None,
45+
parent_sha: typing.Optional[str] = None,
46+
upload_coverage: bool = False,
4547
args: dict = None,
4648
) -> RequestResult:
4749
data = {
@@ -54,6 +56,12 @@ def send_upload_data(
5456
"name": name,
5557
"version": codecov_cli_version,
5658
}
59+
if upload_coverage:
60+
data["branch"] = branch
61+
data["code"] = report_code
62+
data["commitid"] = commit_sha
63+
data["parent_commit_id"] = parent_sha
64+
data["pullid"] = pull_request_number
5765
headers = get_token_header(token)
5866
encoded_slug = encode_slug(slug)
5967
upload_url = enterprise_url or CODECOV_INGEST_URL
@@ -66,6 +74,7 @@ def send_upload_data(
6674
encoded_slug,
6775
commit_sha,
6876
report_code,
77+
upload_coverage,
6978
)
7079
# Data that goes to storage
7180
reports_payload = self._generate_payload(
@@ -176,9 +185,14 @@ def get_url_and_possibly_update_data(
176185
encoded_slug,
177186
commit_sha,
178187
report_code,
188+
upload_coverage=False,
179189
):
180190
if report_type == "coverage":
181-
url = f"{upload_url}/upload/{git_service}/{encoded_slug}/commits/{commit_sha}/reports/{report_code}/uploads"
191+
base_url = f"{upload_url}/upload/{git_service}/{encoded_slug}"
192+
if upload_coverage:
193+
url = f"{base_url}/upload-coverage"
194+
else:
195+
url = f"{base_url}/commits/{commit_sha}/reports/{report_code}/uploads"
182196
elif report_type == "test_results":
183197
data["slug"] = encoded_slug
184198
data["branch"] = branch
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import pathlib
2+
import typing
3+
4+
from codecov_cli.helpers.ci_adapters.base import CIAdapterBase
5+
from codecov_cli.helpers.versioning_systems import VersioningSystemInterface
6+
from codecov_cli.services.upload import do_upload_logic
7+
8+
9+
def upload_coverage_logic(
10+
cli_config: typing.Dict,
11+
versioning_system: VersioningSystemInterface,
12+
ci_adapter: CIAdapterBase,
13+
*,
14+
branch: typing.Optional[str],
15+
build_code: typing.Optional[str],
16+
build_url: typing.Optional[str],
17+
commit_sha: str,
18+
disable_file_fixes: bool,
19+
disable_search: bool,
20+
dry_run: bool,
21+
enterprise_url: typing.Optional[str],
22+
env_vars: typing.Dict[str, str],
23+
fail_on_error: bool,
24+
files_search_exclude_folders: typing.List[pathlib.Path],
25+
files_search_explicitly_listed_files: typing.List[pathlib.Path],
26+
files_search_root_folder: pathlib.Path,
27+
flags: typing.List[str],
28+
gcov_args: typing.Optional[str],
29+
gcov_executable: typing.Optional[str],
30+
gcov_ignore: typing.Optional[str],
31+
gcov_include: typing.Optional[str],
32+
git_service: typing.Optional[str],
33+
handle_no_reports_found: bool,
34+
job_code: typing.Optional[str],
35+
name: typing.Optional[str],
36+
network_filter: typing.Optional[str],
37+
network_prefix: typing.Optional[str],
38+
network_root_folder: pathlib.Path,
39+
parent_sha: typing.Optional[str],
40+
plugin_names: typing.List[str],
41+
pull_request_number: typing.Optional[str],
42+
report_code: str,
43+
slug: typing.Optional[str],
44+
swift_project: typing.Optional[str],
45+
token: typing.Optional[str],
46+
use_legacy_uploader: bool,
47+
upload_file_type: str = "coverage",
48+
args: dict = None,
49+
):
50+
return do_upload_logic(
51+
cli_config=cli_config,
52+
versioning_system=versioning_system,
53+
ci_adapter=ci_adapter,
54+
upload_coverage=True,
55+
args=args,
56+
branch=branch,
57+
build_code=build_code,
58+
build_url=build_url,
59+
commit_sha=commit_sha,
60+
disable_file_fixes=disable_file_fixes,
61+
disable_search=disable_search,
62+
dry_run=dry_run,
63+
enterprise_url=enterprise_url,
64+
env_vars=env_vars,
65+
fail_on_error=fail_on_error,
66+
files_search_exclude_folders=files_search_exclude_folders,
67+
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
68+
files_search_root_folder=files_search_root_folder,
69+
flags=flags,
70+
gcov_args=gcov_args,
71+
gcov_executable=gcov_executable,
72+
gcov_ignore=gcov_ignore,
73+
gcov_include=gcov_include,
74+
git_service=git_service,
75+
handle_no_reports_found=handle_no_reports_found,
76+
job_code=job_code,
77+
name=name,
78+
network_filter=network_filter,
79+
network_prefix=network_prefix,
80+
network_root_folder=network_root_folder,
81+
parent_sha=parent_sha,
82+
plugin_names=plugin_names,
83+
pull_request_number=pull_request_number,
84+
report_code=report_code,
85+
slug=slug,
86+
swift_project=swift_project,
87+
token=token,
88+
use_legacy_uploader=use_legacy_uploader,
89+
upload_file_type=upload_file_type,
90+
)

0 commit comments

Comments
 (0)