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

Commit 73277a9

Browse files
authored
Merge pull request #166 from codecov/dana/check-head-base-shas
do not run label analysis unless head and base shas are different
2 parents 73a60db + 5726dd0 commit 73277a9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

codecov_cli/commands/labelanalysis.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ def label_analysis(
6969
)
7070
),
7171
)
72+
if head_commit_sha == base_commit_sha:
73+
logger.error(
74+
"Base and head sha can't be the same",
75+
extra=dict(
76+
extra_log_attributes=dict(
77+
head_commit_sha=head_commit_sha,
78+
base_commit_sha=base_commit_sha,
79+
)
80+
),
81+
)
82+
raise click.ClickException(
83+
click.style("Unable to run label analysis", fg="red")
84+
)
7285
upload_url = enterprise_url or CODECOV_API_URL
7386
url = f"{upload_url}/labels/labels-analysis"
7487
token_header = f"Repotoken {token}"

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)