diff --git a/codecov_cli/commands/commit.py b/codecov_cli/commands/commit.py index 5571e3e5..97dbff1c 100644 --- a/codecov_cli/commands/commit.py +++ b/codecov_cli/commands/commit.py @@ -24,7 +24,7 @@ "--pr", "--pull-request-number", "pull_request_number", - help="Specify the pull request number mannually. Used to override pre-existing CI environment variables", + help="Specify the pull request number manually. Used to override pre-existing CI environment variables", cls=CodecovOption, fallback_field=FallbackFieldEnum.pull_request_number, ) diff --git a/codecov_cli/commands/empty_upload.py b/codecov_cli/commands/empty_upload.py index bfb0f39a..463fd81c 100644 --- a/codecov_cli/commands/empty_upload.py +++ b/codecov_cli/commands/empty_upload.py @@ -6,8 +6,8 @@ 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 from codecov_cli.services.empty_upload import empty_upload_logic from codecov_cli.types import CommandContext @@ -16,6 +16,26 @@ @click.command() @click.option("--force", is_flag=True, default=False) +@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 manually. 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, +) @global_options @click.pass_context def empty_upload( @@ -26,11 +46,29 @@ def empty_upload( token: typing.Optional[str], git_service: typing.Optional[str], fail_on_error: typing.Optional[bool], + parent_sha: typing.Optional[str], + pull_request_number: typing.Optional[int], + branch: typing.Optional[str], ): with sentry_sdk.start_transaction(op="task", name="Empty Upload"): with sentry_sdk.start_span(name="empty_upload"): enterprise_url = ctx.obj.get("enterprise_url") args = get_cli_args(ctx) + + logger.debug("Attempting to Create Commit before doing an empty upload.") + create_commit_logic( + commit_sha, + parent_sha, + pull_request_number, + branch, + slug, + token, + git_service, + enterprise_url, + fail_on_error, + args, + ) + logger.debug( "Starting empty upload process", extra=dict( diff --git a/codecov_cli/commands/report.py b/codecov_cli/commands/report.py index 3a0d05ef..280e8492 100644 --- a/codecov_cli/commands/report.py +++ b/codecov_cli/commands/report.py @@ -21,7 +21,7 @@ "--pr", "--pull-request-number", "pull_request_number", - help="Specify the pull request number mannually. Used to override pre-existing CI environment variables", + help="Specify the pull request number manually. Used to override pre-existing CI environment variables", cls=CodecovOption, fallback_field=FallbackFieldEnum.pull_request_number, ) diff --git a/codecov_cli/commands/upload.py b/codecov_cli/commands/upload.py index 5bf5c7dd..2b283002 100644 --- a/codecov_cli/commands/upload.py +++ b/codecov_cli/commands/upload.py @@ -124,7 +124,7 @@ def _turn_env_vars_into_dict(ctx, params, value): "--pr", "--pull-request-number", "pull_request_number", - help="Specify the pull request number mannually. Used to override pre-existing CI environment variables", + help="Specify the pull request number manually. Used to override pre-existing CI environment variables", cls=CodecovOption, fallback_field=FallbackFieldEnum.pull_request_number, ), diff --git a/codecovcli_commands b/codecovcli_commands index 95724a66..22391fc0 100644 --- a/codecovcli_commands +++ b/codecovcli_commands @@ -31,7 +31,7 @@ Options: --parent-sha TEXT SHA (with 40 chars) of what should be the parent of this commit -P, --pr, --pull-request-number TEXT - Specify the pull request number mannually. + Specify the pull request number manually. Used to override pre-existing CI environment variables -B, --branch TEXT Branch to which this commit belongs to @@ -49,7 +49,7 @@ Options: --code TEXT The code of the report. If unsure, leave default -P, --pr, --pull-request-number TEXT - Specify the pull request number mannually. + Specify the pull request number manually. Used to override pre-existing CI environment variables -C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required] @@ -109,7 +109,7 @@ Options: in Codecov UI -B, --branch TEXT Branch to which this commit belongs to -P, --pr, --pull-request-number TEXT - Specify the pull request number mannually. + Specify the pull request number manually. Used to override pre-existing CI environment variables -e, --env, --env-var TEXT Specify environment variables to be included @@ -151,6 +151,13 @@ Usage: codecovcli empty-upload [OPTIONS] Options: --force + --parent-sha TEXT SHA (with 40 chars) of what should be the + parent of this commit + -P, --pr, --pull-request-number TEXT + Specify the pull request number manually. + Used to override pre-existing CI environment + variables + -B, --branch TEXT Branch to which this commit belongs to -C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required] -Z, --fail-on-error Exit with non-zero code in case of error --git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server] @@ -293,7 +300,7 @@ Options: in Codecov UI -B, --branch TEXT Branch to which this commit belongs to -P, --pr, --pull-request-number TEXT - Specify the pull request number mannually. + Specify the pull request number manually. Used to override pre-existing CI environment variables -e, --env, --env-var TEXT Specify environment variables to be included @@ -369,7 +376,7 @@ Options: in Codecov UI -B, --branch TEXT Branch to which this commit belongs to -P, --pr, --pull-request-number TEXT - Specify the pull request number mannually. + Specify the pull request number manually. Used to override pre-existing CI environment variables -e, --env, --env-var TEXT Specify environment variables to be included diff --git a/pyproject.toml b/pyproject.toml index 2f7ff34e..eecab18b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "regex", "responses==0.21.*", "sentry-sdk>=2.20.0", - "test-results-parser==0.5.*", + "test-results-parser==0.5.4", "tree-sitter==0.20.*", "wrapt>=1.17.2", ] diff --git a/tests/commands/test_invoke_empty_upload.py b/tests/commands/test_invoke_empty_upload.py new file mode 100644 index 00000000..d38a1a79 --- /dev/null +++ b/tests/commands/test_invoke_empty_upload.py @@ -0,0 +1,25 @@ +from click.testing import CliRunner + +from codecov_cli.fallbacks import FallbackFieldEnum +from codecov_cli.main import cli +from tests.factory import FakeProvider, FakeVersioningSystem + +def test_invoke_empty_upload_with_create_commit(mocker): + create_commit_mock = mocker.patch("codecov_cli.commands.empty_upload.create_commit_logic") + empty_upload_mock = mocker.patch("codecov_cli.commands.empty_upload.empty_upload_logic") + + fake_ci_provider = FakeProvider({FallbackFieldEnum.commit_sha: None}) + mocker.patch("codecov_cli.main.get_ci_adapter", return_value=fake_ci_provider) + + runner = CliRunner() + result = runner.invoke(cli, ["empty-upload", + "-C", "command-sha", + "--slug", "owner/repo", + "--parent-sha", "asdf", + "--branch", "main", + "--pr", 1234], obj={}) + assert result.exit_code == 0 + + create_commit_mock.assert_called_once() + empty_upload_mock.assert_called_once() + diff --git a/tests/commands/test_invoke_upload_coverage.py b/tests/commands/test_invoke_upload_coverage.py index da1876e9..58e6507f 100644 --- a/tests/commands/test_invoke_upload_coverage.py +++ b/tests/commands/test_invoke_upload_coverage.py @@ -106,8 +106,8 @@ def test_upload_coverage_options(mocker): " Codecov UI", " -B, --branch TEXT Branch to which this commit belongs to", " -P, --pr, --pull-request-number TEXT", - " Specify the pull request number mannually.", - " Used to override pre-existing CI environment", + " Specify the pull request number manually. Used", + " to override pre-existing CI environment", " variables", " -e, --env, --env-var TEXT Specify environment variables to be included", " with this build.", diff --git a/tests/commands/test_invoke_upload_process.py b/tests/commands/test_invoke_upload_process.py index 998bc430..967e0dfe 100644 --- a/tests/commands/test_invoke_upload_process.py +++ b/tests/commands/test_invoke_upload_process.py @@ -106,8 +106,8 @@ def test_upload_process_options(mocker): " Codecov UI", " -B, --branch TEXT Branch to which this commit belongs to", " -P, --pr, --pull-request-number TEXT", - " Specify the pull request number mannually.", - " Used to override pre-existing CI environment", + " Specify the pull request number manually. Used", + " to override pre-existing CI environment", " variables", " -e, --env, --env-var TEXT Specify environment variables to be included", " with this build.",