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

Commit 065b3df

Browse files
committed
do not run label analysis unless head and base shas are different
1 parent ee2889a commit 065b3df

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

codecov_cli/commands/labelanalysis.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ def label_analysis(
6666
)
6767
),
6868
)
69+
if head_commit_sha == base_commit_sha:
70+
logger.error(
71+
"Base and head sha can't be the same",
72+
extra=dict(
73+
extra_log_attributes=dict(
74+
head_commit_sha=head_commit_sha,
75+
base_commit_sha=base_commit_sha,
76+
)
77+
),
78+
)
79+
raise click.ClickException(
80+
click.style("Unable to run label analysis", fg="red")
81+
)
82+
6983
url = "https://api.codecov.io/labels/labels-analysis"
7084
token_header = f"Repotoken {token}"
7185

tests/commands/test_invoke_labelanalysis.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ def test_invoke_label_analysis_missing_base_sha(self, mocker, fake_ci_provider):
8686
assert result.exit_code != 0
8787
assert "Error: Missing option '--base-sha'." in result.output
8888

89+
def test_invoke_label_analysis_base_sha_same_as_head_sha(
90+
self, mocker, fake_ci_provider
91+
):
92+
mocker.patch("codecov_cli.main.get_ci_adapter", return_value=fake_ci_provider)
93+
runner = CliRunner()
94+
95+
result = runner.invoke(
96+
cli,
97+
[
98+
"label-analysis",
99+
"--token=STATIC_TOKEN",
100+
"--base-sha=commit-sha",
101+
"--head-sha=commit-sha",
102+
],
103+
obj={},
104+
)
105+
assert result.exit_code != 0
106+
assert "Base and head sha can't be the same" in result.output
107+
89108
def test_invoke_label_analysis(self, get_labelanalysis_deps, mocker):
90109
mock_get_runner = get_labelanalysis_deps["mock_get_runner"]
91110
fake_runner = get_labelanalysis_deps["fake_runner"]

0 commit comments

Comments
 (0)