Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: coverage_drop condition #529

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion services/notification/notifiers/comment/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ async def _check_coverage_drop(comparison: ComparisonProxy) -> bool:
project_status_config = read_yaml_field(
comparison.comparison.current_yaml, ("coverage", "status", "project"), {}
)
threshold = Decimal(project_status_config.get("threshold", 0))
threshold = 0
if isinstance(project_status_config, dict):
# Project status can also be a bool value, so check is needed
threshold = Decimal(project_status_config.get("threshold", 0))
Copy link
Contributor

@adrian-codecov adrian-codecov Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean for project to be a bool? If set to True, what value does it use as a threshold?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the project status is a bool it means "I want project status with the default configuration". The default threshold is 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, ty for clarifying

target_coverage = Decimal(
comparison.project_coverage_base.report.totals.coverage
).quantize(Decimal("0.00000"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
CoverageCommentRequiredChanges,
CoverageCommentRequiredChangesANDGroup,
)
from shared.yaml import UserYaml

from database.models.core import Repository
from services.comparison import ComparisonProxy
from services.notification.notifiers.comment import CommentNotifier
from services.notification.notifiers.comment.conditions import HasEnoughRequiredChanges

Expand Down Expand Up @@ -216,3 +218,42 @@ async def test_uncovered_patch(
)
== expected
)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"comparison_name, yaml, expected",
[
pytest.param("sample_comparison", {}, False, id="positive_change"),
pytest.param(
"sample_comparison_negative_change",
{},
True,
id="negative_change_no_extra_config",
),
pytest.param(
"sample_comparison_negative_change",
{"coverage": {"status": {"project": True}}},
True,
id="negative_change_bool_config",
),
pytest.param(
"sample_comparison_negative_change",
{"coverage": {"status": {"project": {"threshold": 10}}}},
False,
id="negative_change_high_threshold",
),
],
)
async def test_coverage_drop_with_different_project_configs(
comparison_name, yaml, expected, request
):
comparison: ComparisonProxy = request.getfixturevalue(comparison_name)
comparison.comparison.current_yaml = UserYaml(yaml)
notifier = _get_notifier(
comparison.head.commit.repository,
[CoverageCommentRequiredChanges.coverage_drop.value],
)
assert (
await HasEnoughRequiredChanges.check_condition(notifier, comparison) == expected
)
Loading