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

Commit 019a55a

Browse files
feat: add force flag to empty upload (#362)
* feat: add force flag to empty upload * fix: change format of option for empty upload force Signed-off-by: joseph-sentry <[email protected]>
1 parent ef19810 commit 019a55a

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

codecov_cli/commands/empty_upload.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313

1414
@click.command()
15+
@click.option("--force", is_flag=True, default=False)
1516
@global_options
1617
@click.pass_context
1718
def empty_upload(
1819
ctx,
1920
commit_sha: str,
21+
force: bool,
2022
slug: typing.Optional[str],
2123
token: typing.Optional[str],
2224
git_service: typing.Optional[str],
@@ -37,5 +39,5 @@ def empty_upload(
3739
),
3840
)
3941
return empty_upload_logic(
40-
commit_sha, slug, token, git_service, enterprise_url, fail_on_error
42+
commit_sha, slug, token, git_service, enterprise_url, fail_on_error, force
4143
)

codecov_cli/services/empty_upload/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414

1515
def empty_upload_logic(
16-
commit_sha, slug, token, git_service, enterprise_url, fail_on_error
16+
commit_sha, slug, token, git_service, enterprise_url, fail_on_error, should_force
1717
):
1818
encoded_slug = encode_slug(slug)
1919
headers = get_token_header_or_fail(token)
2020
upload_url = enterprise_url or CODECOV_API_URL
2121
url = f"{upload_url}/upload/{git_service}/{encoded_slug}/commits/{commit_sha}/empty-upload"
22-
sending_result = send_post_request(url=url, headers=headers)
22+
sending_result = send_post_request(
23+
url=url, headers=headers, data={"should_force": should_force}
24+
)
2325
log_warnings_and_errors_if_any(sending_result, "Empty Upload", fail_on_error)
2426
if sending_result.status_code == 200:
2527
response_json = json.loads(sending_result.text)

tests/services/empty_upload/test_empty_upload.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_empty_upload_with_warnings(mocker):
2121
runner = CliRunner()
2222
with runner.isolation() as outstreams:
2323
res = empty_upload_logic(
24-
"commit_sha", "owner/repo", uuid.uuid4(), "service", None, False
24+
"commit_sha", "owner/repo", uuid.uuid4(), "service", None, False, False
2525
)
2626
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
2727
assert out_bytes == [
@@ -50,7 +50,7 @@ def test_empty_upload_with_error(mocker):
5050
runner = CliRunner()
5151
with runner.isolation() as outstreams:
5252
res = empty_upload_logic(
53-
"commit_sha", "owner/repo", uuid.uuid4(), "service", None, False
53+
"commit_sha", "owner/repo", uuid.uuid4(), "service", None, False, False
5454
)
5555

5656
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
@@ -77,7 +77,7 @@ def test_empty_upload_200(mocker):
7777
runner = CliRunner()
7878
with runner.isolation() as outstreams:
7979
res = empty_upload_logic(
80-
"commit_sha", "owner/repo", token, "service", None, False
80+
"commit_sha", "owner/repo", token, "service", None, False, False
8181
)
8282
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
8383
assert out_bytes == [
@@ -96,10 +96,40 @@ def test_empty_upload_403(mocker):
9696
return_value=mocker.MagicMock(status_code=403, text="Permission denied"),
9797
)
9898
token = uuid.uuid4()
99-
res = empty_upload_logic("commit_sha", "owner/repo", token, "service", None, False)
99+
res = empty_upload_logic(
100+
"commit_sha", "owner/repo", token, "service", None, False, False
101+
)
100102
assert res.error == RequestError(
101103
code="HTTP Error 403",
102104
description="Permission denied",
103105
params={},
104106
)
105107
mocked_response.assert_called_once()
108+
109+
110+
def test_empty_upload_force(mocker):
111+
res = {
112+
"result": "Force option was enabled. Triggering passing notifications.",
113+
"non_ignored_files": [],
114+
}
115+
mocked_response = mocker.patch(
116+
"codecov_cli.helpers.request.requests.post",
117+
return_value=RequestResult(
118+
status_code=200, error=None, warnings=[], text=json.dumps(res)
119+
),
120+
)
121+
token = uuid.uuid4()
122+
runner = CliRunner()
123+
with runner.isolation() as outstreams:
124+
res = empty_upload_logic(
125+
"commit_sha", "owner/repo", token, "service", None, False, True
126+
)
127+
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
128+
assert out_bytes == [
129+
("info", "Process Empty Upload complete"),
130+
("info", "Force option was enabled. Triggering passing notifications."),
131+
("info", "Non ignored files []"),
132+
]
133+
assert res.error is None
134+
assert res.warnings == []
135+
mocked_response.assert_called_once()

0 commit comments

Comments
 (0)