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

feat: collect additional params from cli usage #506

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions codecov_cli/commands/base_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.encoder import slug_without_subgroups_is_invalid
from codecov_cli.services.commit.base_picking import base_picking_logic
from codecov_cli.types import CommandContext
Expand Down Expand Up @@ -54,16 +55,11 @@ def pr_base_picking(
service: typing.Optional[str],
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Starting base picking process",
extra=dict(
extra_log_attributes=dict(
pr=pr,
slug=slug,
token=token,
service=service,
enterprise_url=enterprise_url,
)
extra_log_attributes=args,
),
)

Expand All @@ -73,4 +69,4 @@ def pr_base_picking(
)
return

base_picking_logic(base_sha, pr, slug, token, service, enterprise_url)
base_picking_logic(base_sha, pr, slug, token, service, enterprise_url, args)
14 changes: 4 additions & 10 deletions codecov_cli/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.commit import create_commit_logic
Expand Down Expand Up @@ -47,19 +48,11 @@ def create_commit(
fail_on_error: bool,
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Starting create commit process",
extra=dict(
extra_log_attributes=dict(
commit_sha=commit_sha,
parent_sha=parent_sha,
pr=pull_request_number,
branch=branch,
slug=slug,
token=token,
service=git_service,
enterprise_url=enterprise_url,
)
extra_log_attributes=args,
),
)
create_commit_logic(
Expand All @@ -72,4 +65,5 @@ def create_commit(
git_service,
enterprise_url,
fail_on_error,
args,
)
13 changes: 4 additions & 9 deletions codecov_cli/commands/create_report_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import click

from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.options import global_options
from codecov_cli.services.report import create_report_results_logic
from codecov_cli.types import CommandContext
Expand All @@ -25,19 +26,13 @@ def create_report_results(
fail_on_error: bool,
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Creating report results",
extra=dict(
extra_log_attributes=dict(
commit_sha=commit_sha,
code=code,
slug=slug,
service=git_service,
enterprise_url=enterprise_url,
token=token,
)
extra_log_attributes=args,
),
)
create_report_results_logic(
commit_sha, code, slug, git_service, token, enterprise_url, fail_on_error
commit_sha, code, slug, git_service, token, enterprise_url, fail_on_error, args
)
13 changes: 4 additions & 9 deletions codecov_cli/commands/empty_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.empty_upload import empty_upload_logic
Expand All @@ -26,19 +27,13 @@ def empty_upload(
fail_on_error: typing.Optional[bool],
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Starting empty upload process",
extra=dict(
extra_log_attributes=dict(
commit_sha=commit_sha,
slug=slug,
token=token,
service=git_service,
enterprise_url=enterprise_url,
fail_on_error=fail_on_error,
)
extra_log_attributes=args,
),
)
return empty_upload_logic(
commit_sha, slug, token, git_service, enterprise_url, fail_on_error, force
commit_sha, slug, token, git_service, enterprise_url, fail_on_error, force, args
)
10 changes: 2 additions & 8 deletions codecov_cli/commands/get_report_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ def get_report_results(
fail_on_error: bool,
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Getting report results",
extra=dict(
extra_log_attributes=dict(
commit_sha=commit_sha,
code=code,
slug=slug,
service=git_service,
enterprise_url=enterprise_url,
token=token,
)
extra_log_attributes=args,
),
)
encoded_slug = encode_slug(slug)
Expand Down
12 changes: 3 additions & 9 deletions codecov_cli/commands/labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers import request
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.config import CODECOV_API_URL
from codecov_cli.helpers.validators import validate_commit_sha
from codecov_cli.runners import get_runner
Expand Down Expand Up @@ -89,18 +90,11 @@ def label_analysis(
runner_params: List[str],
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Starting label analysis",
extra=dict(
extra_log_attributes=dict(
head_commit_sha=head_commit_sha,
base_commit_sha=base_commit_sha,
token=token,
runner_name=runner_name,
enterprise_url=enterprise_url,
max_wait_time=max_wait_time,
dry_run=dry_run,
)
extra_log_attributes=args,
),
)
if head_commit_sha == base_commit_sha:
Expand Down
24 changes: 20 additions & 4 deletions codecov_cli/commands/process_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
parse_junit_xml,
)

from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.request import (
log_warnings_and_errors_if_any,
send_post_request,
)
from codecov_cli.services.upload.file_finder import select_file_finder
from codecov_cli.types import CommandContext

logger = logging.getLogger("codecovcli")

Expand Down Expand Up @@ -83,8 +85,14 @@ class TestResultsNotificationPayload:

@click.command()
@process_test_results_options
@click.pass_context
def process_test_results(
dir=None, files=None, exclude_folders=None, disable_search=None, provider_token=None
ctx: CommandContext,
dir=None,
files=None,
exclude_folders=None,
disable_search=None,
provider_token=None,
):
if provider_token is None:
raise click.ClickException(
Expand Down Expand Up @@ -130,10 +138,11 @@ def process_test_results(
# GITHUB_REF is documented here: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
pr_number = ref.split("/")[2]

create_github_comment(provider_token, slug, pr_number, message)
args = get_cli_args(ctx)
create_github_comment(provider_token, slug, pr_number, message, args)


def create_github_comment(token, repo_slug, pr_number, message):
def create_github_comment(token, repo_slug, pr_number, message, args):
url = f"https://api.github.com/repos/{repo_slug}/issues/{pr_number}/comments"

headers = {
Expand All @@ -144,7 +153,14 @@ def create_github_comment(token, repo_slug, pr_number, message):
logger.info("Posting github comment")

log_warnings_and_errors_if_any(
send_post_request(url=url, data={"body": message}, headers=headers),
send_post_request(
url=url,
data={
"body": message,
"cli_args": args,
},
headers=headers,
),
"Posting test results comment",
)

Expand Down
12 changes: 4 additions & 8 deletions codecov_cli/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.options import global_options
from codecov_cli.services.report import create_report_logic
from codecov_cli.types import CommandContext
Expand Down Expand Up @@ -36,17 +37,11 @@ def create_report(
pull_request_number: int,
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Starting create report process",
extra=dict(
extra_log_attributes=dict(
commit_sha=commit_sha,
code=code,
slug=slug,
service=git_service,
enterprise_url=enterprise_url,
token=token,
)
extra_log_attributes=args,
),
)
res = create_report_logic(
Expand All @@ -58,6 +53,7 @@ def create_report(
enterprise_url,
pull_request_number,
fail_on_error,
args,
)
if not res.error:
logger.info(
Expand Down
11 changes: 4 additions & 7 deletions codecov_cli/commands/send_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.upload_completion import upload_completion_logic
Expand All @@ -24,16 +25,11 @@ def send_notifications(
fail_on_error: bool,
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Sending notifications process has started",
extra=dict(
extra_log_attributes=dict(
commit_sha=commit_sha,
slug=slug,
token=token,
service=git_service,
enterprise_url=enterprise_url,
)
extra_log_attributes=args,
),
)
return upload_completion_logic(
Expand All @@ -43,4 +39,5 @@ def send_notifications(
git_service,
enterprise_url,
fail_on_error,
args,
)
14 changes: 4 additions & 10 deletions codecov_cli/commands/staticanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.validators import validate_commit_sha
from codecov_cli.services.staticanalysis import run_analysis_entrypoint
from codecov_cli.types import CommandContext
Expand Down Expand Up @@ -59,19 +60,11 @@ def static_analysis(
folders_to_exclude: typing.List[pathlib.Path],
):
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Starting Static Analysis processing",
extra=dict(
extra_log_attributes=dict(
foldertosearch=foldertosearch,
numberprocesses=numberprocesses,
pattern=pattern,
commit_sha=commit,
token=token,
force=force,
folders_to_exclude=folders_to_exclude,
enterprise_url=enterprise_url,
)
extra_log_attributes=args,
),
)
return asyncio.run(
Expand All @@ -85,5 +78,6 @@ def static_analysis(
force,
list(folders_to_exclude),
enterprise_url,
args,
)
)
31 changes: 4 additions & 27 deletions codecov_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import click

from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.options import global_options
from codecov_cli.services.upload import do_upload_logic
from codecov_cli.types import CommandContext
Expand Down Expand Up @@ -225,36 +226,11 @@ def do_upload(
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)
logger.debug(
"Starting upload processing",
extra=dict(
extra_log_attributes=dict(
branch=branch,
build_code=build_code,
build_url=build_url,
commit_sha=commit_sha,
disable_file_fixes=disable_file_fixes,
disable_search=disable_search,
enterprise_url=enterprise_url,
env_vars=env_vars,
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,
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,
slug=slug,
token=token,
upload_file_type=report_type,
)
extra_log_attributes=args,
),
)
do_upload_logic(
Expand Down Expand Up @@ -289,4 +265,5 @@ def do_upload(
token=token,
upload_file_type=report_type,
use_legacy_uploader=use_legacy_uploader,
args=args,
)
Loading
Loading