Skip to content

Commit

Permalink
Single endpoint coverage command initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-codecov committed Nov 6, 2024
1 parent db6ab02 commit d1b329f
Show file tree
Hide file tree
Showing 4 changed files with 477 additions and 2 deletions.
288 changes: 288 additions & 0 deletions codecov_cli/commands/combined_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
import logging
import os
import pathlib
import typing

import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.git import GitService
from codecov_cli.helpers.options import global_options
from codecov_cli.services.combined_upload import combined_upload_logic
from codecov_cli.types import CommandContext

logger = logging.getLogger("codecovcli")


def _turn_env_vars_into_dict(ctx, params, value):
return dict((v, os.getenv(v, None)) for v in value)

@click.command()
@click.option(
"--parent-sha",
help="SHA (with 40 chars) of what should be the parent of this commit",
)
@click.option(
"-P",
"--pr",
"--pull-request-number",
"pull_request_number",
help="Specify the pull request number mannually. Used to override pre-existing CI environment variables",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.pull_request_number,
)
@click.option(
"-B",
"--branch",
help="Branch to which this commit belongs to",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.branch,
)
@click.option(
"--code",
"--report-code",
"report_code",
help="The code of the report. If unsure, leave default",
default="default",
)
@click.option(
"--network-root-folder",
help="Root folder from which to consider paths on the network section",
type=click.Path(path_type=pathlib.Path),
default=pathlib.Path.cwd,
show_default="Current working directory",
)
@click.option(
"-s",
"--dir",
"--coverage-files-search-root-folder",
"--files-search-root-folder",
"files_search_root_folder",
help="Folder where to search for coverage files",
type=click.Path(path_type=pathlib.Path),
default=pathlib.Path.cwd,
show_default="Current Working Directory",
)
@click.option(
"--exclude",
"--coverage-files-search-exclude-folder",
"--files-search-exclude-folder",
"files_search_exclude_folders",
help="Folders to exclude from search",
type=click.Path(path_type=pathlib.Path),
multiple=True,
default=[],
)
@click.option(
"-f",
"--file",
"--coverage-files-search-direct-file",
"--files-search-direct-file",
"files_search_explicitly_listed_files",
help="Explicit files to upload. These will be added to the coverage files found for upload. If you wish to only upload the specified files, please consider using --disable-search to disable uploading other files.",
type=click.Path(path_type=pathlib.Path),
multiple=True,
default=[],
)
@click.option(
"--disable-search",
help="Disable search for coverage files. This is helpful when specifying what files you want to upload with the --file option.",
is_flag=True,
default=False,
)
@click.option(
"--disable-file-fixes",
help="Disable file fixes to ignore common lines from coverage (e.g. blank lines or empty brackets)",
is_flag=True,
default=False,
)
@click.option(
"-b",
"--build",
"--build-code",
"build_code",
cls=CodecovOption,
help="Specify the build number manually",
fallback_field=FallbackFieldEnum.build_code,
)
@click.option(
"--build-url",
"build_url",
cls=CodecovOption,
help="The URL of the build where this is running",
fallback_field=FallbackFieldEnum.build_url,
)
@click.option(
"--job-code",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.job_code,
)
@click.option(
"-n",
"--name",
help="Custom defined name of the upload. Visible in Codecov UI",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.build_code,
)
@click.option(
"-e",
"--env",
"--env-var",
"env_vars",
multiple=True,
callback=_turn_env_vars_into_dict,
help="Specify environment variables to be included with this build.",
)
@click.option(
"-F",
"--flag",
"flags",
multiple=True,
default=[],
help="Flag the upload to group coverage metrics. Multiple flags allowed.",
)
@click.option(
"--plugin",
"plugin_names",
multiple=True,
default=["xcode", "gcov", "pycoverage"],
)
@click.option(
"-d",
"--dry-run",
"dry_run",
is_flag=True,
help="Don't upload files to Codecov",
)
@click.option(
"--legacy",
"--use-legacy-uploader",
"use_legacy_uploader",
is_flag=True,
help="Use the legacy upload endpoint",
)
@click.option(
"--handle-no-reports-found",
"handle_no_reports_found",
is_flag=True,
help="Raise no excpetions when no coverage reports found.",
)
@click.option(
"--report-type",
help="The type of the file to upload, coverage by default. Possible values are: testing, coverage.",
default="coverage",
type=click.Choice(["coverage", "test_results"]),
)
@click.option(
"--network-filter",
help="Specify a filter on the files listed in the network section of the Codecov report. This will only add files whose path begin with the specified filter. Useful for upload-specific path fixing",
)
@click.option(
"--network-prefix",
help="Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing",
)
@click.option(
"--gcov-args",
help="Extra arguments to pass to gcov",
)
@click.option(
"--gcov-ignore",
help="Paths to ignore during gcov gathering",
)
@click.option(
"--gcov-include",
help="Paths to include during gcov gathering",
)
@click.option(
"--gcov-executable",
help="gcov executable to run. Defaults to 'gcov'",
)
@click.option(
"--swift-project",
help="Specify the swift project",
)
@global_options
@click.pass_context
def combined_upload(
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,
):
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)
combined_upload_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,
)
3 changes: 2 additions & 1 deletion codecov_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from codecov_cli import __version__
from codecov_cli.commands.base_picking import pr_base_picking
from codecov_cli.commands.combined_upload import combined_upload
from codecov_cli.commands.commit import create_commit
from codecov_cli.commands.create_report_result import create_report_results
from codecov_cli.commands.empty_upload import empty_upload
Expand Down Expand Up @@ -64,7 +65,7 @@ def cli(
ctx.default_map = {ctx.invoked_subcommand: {"token": token}}
ctx.obj["enterprise_url"] = enterprise_url


cli.add_command(combined_upload)
cli.add_command(do_upload)
cli.add_command(create_commit)
cli.add_command(create_report)
Expand Down
Loading

0 comments on commit d1b329f

Please sign in to comment.