Skip to content

Commit

Permalink
Merge pull request #166 from codecov/dana/check-head-base-shas
Browse files Browse the repository at this point in the history
do not run label analysis unless head and base shas are different
  • Loading branch information
dana-yaish authored May 26, 2023
2 parents 73a60db + 5726dd0 commit 73277a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions codecov_cli/commands/labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ def label_analysis(
)
),
)
if head_commit_sha == base_commit_sha:
logger.error(
"Base and head sha can't be the same",
extra=dict(
extra_log_attributes=dict(
head_commit_sha=head_commit_sha,
base_commit_sha=base_commit_sha,
)
),
)
raise click.ClickException(
click.style("Unable to run label analysis", fg="red")
)
upload_url = enterprise_url or CODECOV_API_URL
url = f"{upload_url}/labels/labels-analysis"
token_header = f"Repotoken {token}"
Expand Down
19 changes: 19 additions & 0 deletions tests/commands/test_invoke_labelanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ def test_invoke_label_analysis_missing_base_sha(self, mocker, fake_ci_provider):
assert result.exit_code != 0
assert "Error: Missing option '--base-sha'." in result.output

def test_invoke_label_analysis_base_sha_same_as_head_sha(
self, mocker, fake_ci_provider
):
mocker.patch("codecov_cli.main.get_ci_adapter", return_value=fake_ci_provider)
runner = CliRunner()

result = runner.invoke(
cli,
[
"label-analysis",
"--token=STATIC_TOKEN",
"--base-sha=commit-sha",
"--head-sha=commit-sha",
],
obj={},
)
assert result.exit_code != 0
assert "Base and head sha can't be the same" in result.output

def test_invoke_label_analysis(self, get_labelanalysis_deps, mocker):
mock_get_runner = get_labelanalysis_deps["mock_get_runner"]
fake_runner = get_labelanalysis_deps["fake_runner"]
Expand Down

0 comments on commit 73277a9

Please sign in to comment.