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

have adjusted base comparison use threshold #1056

Merged
merged 1 commit into from
Feb 3, 2025
Merged
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
8 changes: 7 additions & 1 deletion services/notification/notifiers/mixins/status.py
Original file line number Diff line number Diff line change
@@ -303,19 +303,23 @@ def _apply_adjust_base_behavior(
base_adjusted_coverage = (
Decimal(base_adjusted_hits / base_adjusted_totals) * 100
)
threshold = self._get_threshold()

head_coverage = Decimal(comparison.head.report.totals.coverage)
log.info(
"Adjust base applied to project status",
extra=dict(
commit=comparison.head.commit.commitid,
base_adjusted_coverage=base_adjusted_coverage,
threshold=threshold,
head_coverage=head_coverage,
hits_removed=hits_removed,
misses_removed=misses_removed,
partials_removed=partials_removed,
),
)
base_adjusted_coverage = base_adjusted_coverage - threshold

# the head coverage is rounded to five digits after the dot, using shared.helpers.numeric.ratio
# so we should round the base adjusted coverage to the same amount of digits after the dot
# Decimal.quantize: https://docs.python.org/3/library/decimal.html#decimal.Decimal.quantize
@@ -331,13 +335,15 @@ def _apply_adjust_base_behavior(
0,
round_number(self.current_yaml, head_coverage - base_adjusted_coverage),
)
message = f", passed because coverage increased by {rounded_difference}% when compared to adjusted base ({rounded_base_adjusted_coverage}%)"
return (
(
StatusState.success.value,
f", passed because coverage increased by {rounded_difference}% when compared to adjusted base ({rounded_base_adjusted_coverage}%)",
message,
),
helper_text,
)

# use rounded numbers for messages
coverage_rounded = round_number(self.current_yaml, head_coverage)

50 changes: 49 additions & 1 deletion services/notification/notifiers/tests/unit/test_status.py
Original file line number Diff line number Diff line change
@@ -1639,7 +1639,7 @@ def test_adjust_base_behavior(
),
head=FullCommit(commit=CommitFactory(), report=Report(totals=head_totals)),
)
settings = {"target": "auto"}
settings = {"target": "auto", "threshold": "0"}
status_mixin = ProjectStatusNotifier(
repository="repo",
title="fake-notifier",
@@ -1698,6 +1698,54 @@ def test_notify_pass_adjust_base_behavior(
assert result == expected_result
mock_get_impacted_files.assert_called()

def test_notify_pass_adjust_base_behavior_with_threshold(
self, mock_configuration, sample_comparison_negative_change, mocker
):
sample_comparison = sample_comparison_negative_change
mock_get_impacted_files = mocker.patch.object(
ComparisonProxy,
"get_impacted_files",
return_value={
"files": [
{
"base_name": "tests/file1.py",
"head_name": "tests/file1.py",
# Not complete, but we only care about these fields
"removed_diff_coverage": [[1, "h"], [3, "h"], [4, "m"]],
"added_diff_coverage": [],
"unexpected_line_changes": [],
},
{
"base_name": "tests/file2.go",
"head_name": "tests/file2.go",
"removed_diff_coverage": [[1, "h"]],
"added_diff_coverage": [],
"unexpected_line_changes": [],
},
],
},
)
mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br"
notifier = ProjectStatusNotifier(
repository=sample_comparison.head.commit.repository,
title="title",
notifier_yaml_settings={
"removed_code_behavior": "adjust_base",
"threshold": "5",
},
notifier_site_settings=True,
current_yaml=UserYaml({}),
repository_service={},
)
expected_result = {
"message": f"50.00% (-10.00%) compared to {sample_comparison.project_coverage_base.commit.commitid[:7]}, passed because coverage increased by 5.00% when compared to adjusted base (45.00%)",
"state": "success",
"included_helper_text": {},
}
result = notifier.build_payload(sample_comparison)
assert result == expected_result
mock_get_impacted_files.assert_called()

def test_notify_removed_code_behavior_fail(
self, mock_configuration, sample_comparison, mocker
):