Skip to content

Commit 30cba3f

Browse files
Add create commit to empty-upload command (#654)
* Add create commit to empty-upload command This is so that we can also create the commit before uploading. The create-commit is optional (i.e. if users don't pass in values, then their workflow shouldn't break). It will only create a commit if the values are passed. * Force new version for test-results-parser This is because build is failing for 3.13 * Fix spelling of commands
1 parent 079f01b commit 30cba3f

9 files changed

+84
-14
lines changed

codecov_cli/commands/commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"--pr",
2525
"--pull-request-number",
2626
"pull_request_number",
27-
help="Specify the pull request number mannually. Used to override pre-existing CI environment variables",
27+
help="Specify the pull request number manually. Used to override pre-existing CI environment variables",
2828
cls=CodecovOption,
2929
fallback_field=FallbackFieldEnum.pull_request_number,
3030
)

codecov_cli/commands/empty_upload.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
88
from codecov_cli.helpers.args import get_cli_args
9-
from codecov_cli.helpers.git import GitService
109
from codecov_cli.helpers.options import global_options
10+
from codecov_cli.services.commit import create_commit_logic
1111
from codecov_cli.services.empty_upload import empty_upload_logic
1212
from codecov_cli.types import CommandContext
1313

@@ -16,6 +16,26 @@
1616

1717
@click.command()
1818
@click.option("--force", is_flag=True, default=False)
19+
@click.option(
20+
"--parent-sha",
21+
help="SHA (with 40 chars) of what should be the parent of this commit",
22+
)
23+
@click.option(
24+
"-P",
25+
"--pr",
26+
"--pull-request-number",
27+
"pull_request_number",
28+
help="Specify the pull request number manually. Used to override pre-existing CI environment variables",
29+
cls=CodecovOption,
30+
fallback_field=FallbackFieldEnum.pull_request_number,
31+
)
32+
@click.option(
33+
"-B",
34+
"--branch",
35+
help="Branch to which this commit belongs to",
36+
cls=CodecovOption,
37+
fallback_field=FallbackFieldEnum.branch,
38+
)
1939
@global_options
2040
@click.pass_context
2141
def empty_upload(
@@ -26,11 +46,29 @@ def empty_upload(
2646
token: typing.Optional[str],
2747
git_service: typing.Optional[str],
2848
fail_on_error: typing.Optional[bool],
49+
parent_sha: typing.Optional[str],
50+
pull_request_number: typing.Optional[int],
51+
branch: typing.Optional[str],
2952
):
3053
with sentry_sdk.start_transaction(op="task", name="Empty Upload"):
3154
with sentry_sdk.start_span(name="empty_upload"):
3255
enterprise_url = ctx.obj.get("enterprise_url")
3356
args = get_cli_args(ctx)
57+
58+
logger.debug("Attempting to Create Commit before doing an empty upload.")
59+
create_commit_logic(
60+
commit_sha,
61+
parent_sha,
62+
pull_request_number,
63+
branch,
64+
slug,
65+
token,
66+
git_service,
67+
enterprise_url,
68+
fail_on_error,
69+
args,
70+
)
71+
3472
logger.debug(
3573
"Starting empty upload process",
3674
extra=dict(

codecov_cli/commands/report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"--pr",
2222
"--pull-request-number",
2323
"pull_request_number",
24-
help="Specify the pull request number mannually. Used to override pre-existing CI environment variables",
24+
help="Specify the pull request number manually. Used to override pre-existing CI environment variables",
2525
cls=CodecovOption,
2626
fallback_field=FallbackFieldEnum.pull_request_number,
2727
)

codecov_cli/commands/upload.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _turn_env_vars_into_dict(ctx, params, value):
124124
"--pr",
125125
"--pull-request-number",
126126
"pull_request_number",
127-
help="Specify the pull request number mannually. Used to override pre-existing CI environment variables",
127+
help="Specify the pull request number manually. Used to override pre-existing CI environment variables",
128128
cls=CodecovOption,
129129
fallback_field=FallbackFieldEnum.pull_request_number,
130130
),

codecovcli_commands

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Options:
3131
--parent-sha TEXT SHA (with 40 chars) of what should be the
3232
parent of this commit
3333
-P, --pr, --pull-request-number TEXT
34-
Specify the pull request number mannually.
34+
Specify the pull request number manually.
3535
Used to override pre-existing CI environment
3636
variables
3737
-B, --branch TEXT Branch to which this commit belongs to
@@ -49,7 +49,7 @@ Options:
4949
--code TEXT The code of the report. If unsure, leave
5050
default
5151
-P, --pr, --pull-request-number TEXT
52-
Specify the pull request number mannually.
52+
Specify the pull request number manually.
5353
Used to override pre-existing CI environment
5454
variables
5555
-C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required]
@@ -109,7 +109,7 @@ Options:
109109
in Codecov UI
110110
-B, --branch TEXT Branch to which this commit belongs to
111111
-P, --pr, --pull-request-number TEXT
112-
Specify the pull request number mannually.
112+
Specify the pull request number manually.
113113
Used to override pre-existing CI environment
114114
variables
115115
-e, --env, --env-var TEXT Specify environment variables to be included
@@ -151,6 +151,13 @@ Usage: codecovcli empty-upload [OPTIONS]
151151

152152
Options:
153153
--force
154+
--parent-sha TEXT SHA (with 40 chars) of what should be the
155+
parent of this commit
156+
-P, --pr, --pull-request-number TEXT
157+
Specify the pull request number manually.
158+
Used to override pre-existing CI environment
159+
variables
160+
-B, --branch TEXT Branch to which this commit belongs to
154161
-C, --sha, --commit-sha TEXT Commit SHA (with 40 chars) [required]
155162
-Z, --fail-on-error Exit with non-zero code in case of error
156163
--git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]
@@ -293,7 +300,7 @@ Options:
293300
in Codecov UI
294301
-B, --branch TEXT Branch to which this commit belongs to
295302
-P, --pr, --pull-request-number TEXT
296-
Specify the pull request number mannually.
303+
Specify the pull request number manually.
297304
Used to override pre-existing CI environment
298305
variables
299306
-e, --env, --env-var TEXT Specify environment variables to be included
@@ -369,7 +376,7 @@ Options:
369376
in Codecov UI
370377
-B, --branch TEXT Branch to which this commit belongs to
371378
-P, --pr, --pull-request-number TEXT
372-
Specify the pull request number mannually.
379+
Specify the pull request number manually.
373380
Used to override pre-existing CI environment
374381
variables
375382
-e, --env, --env-var TEXT Specify environment variables to be included

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies = [
1818
"regex",
1919
"responses==0.21.*",
2020
"sentry-sdk>=2.20.0",
21-
"test-results-parser==0.5.*",
21+
"test-results-parser==0.5.4",
2222
"tree-sitter==0.20.*",
2323
"wrapt>=1.17.2",
2424
]
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from click.testing import CliRunner
2+
3+
from codecov_cli.fallbacks import FallbackFieldEnum
4+
from codecov_cli.main import cli
5+
from tests.factory import FakeProvider, FakeVersioningSystem
6+
7+
def test_invoke_empty_upload_with_create_commit(mocker):
8+
create_commit_mock = mocker.patch("codecov_cli.commands.empty_upload.create_commit_logic")
9+
empty_upload_mock = mocker.patch("codecov_cli.commands.empty_upload.empty_upload_logic")
10+
11+
fake_ci_provider = FakeProvider({FallbackFieldEnum.commit_sha: None})
12+
mocker.patch("codecov_cli.main.get_ci_adapter", return_value=fake_ci_provider)
13+
14+
runner = CliRunner()
15+
result = runner.invoke(cli, ["empty-upload",
16+
"-C", "command-sha",
17+
"--slug", "owner/repo",
18+
"--parent-sha", "asdf",
19+
"--branch", "main",
20+
"--pr", 1234], obj={})
21+
assert result.exit_code == 0
22+
23+
create_commit_mock.assert_called_once()
24+
empty_upload_mock.assert_called_once()
25+

tests/commands/test_invoke_upload_coverage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ def test_upload_coverage_options(mocker):
106106
" Codecov UI",
107107
" -B, --branch TEXT Branch to which this commit belongs to",
108108
" -P, --pr, --pull-request-number TEXT",
109-
" Specify the pull request number mannually.",
110-
" Used to override pre-existing CI environment",
109+
" Specify the pull request number manually. Used",
110+
" to override pre-existing CI environment",
111111
" variables",
112112
" -e, --env, --env-var TEXT Specify environment variables to be included",
113113
" with this build.",

tests/commands/test_invoke_upload_process.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ def test_upload_process_options(mocker):
106106
" Codecov UI",
107107
" -B, --branch TEXT Branch to which this commit belongs to",
108108
" -P, --pr, --pull-request-number TEXT",
109-
" Specify the pull request number mannually.",
110-
" Used to override pre-existing CI environment",
109+
" Specify the pull request number manually. Used",
110+
" to override pre-existing CI environment",
111111
" variables",
112112
" -e, --env, --env-var TEXT Specify environment variables to be included",
113113
" with this build.",

0 commit comments

Comments
 (0)