-
Notifications
You must be signed in to change notification settings - Fork 10
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
Failed check and status messaging in comment, part I #1014
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import logging | ||
from decimal import Decimal, InvalidOperation | ||
from enum import Enum | ||
from typing import Literal, TypedDict | ||
|
||
from services.comparison import ComparisonProxy, FilteredComparison | ||
from services.yaml.reader import round_number | ||
|
@@ -13,7 +14,35 @@ class StatusState(Enum): | |
failure = "failure" | ||
|
||
|
||
class StatusResult(TypedDict): | ||
""" | ||
The mixins in this file do the calculations and decide the SuccessState for all Status and Checks Notifiers. | ||
Checks have different fields than Statuses, so Checks are converted to the CheckResult type later. | ||
""" | ||
|
||
state: Literal["success", "failure"] # StatusState values | ||
message: str | ||
included_helper_text: dict[str, str] | ||
|
||
|
||
CUSTOM_TARGET_TEXT_PATCH_KEY = "custom_target_helper_text_patch" | ||
CUSTOM_TARGET_TEXT_PROJECT_KEY = "custom_target_helper_text_project" | ||
CUSTOM_TARGET_TEXT_VALUE = ( | ||
"Your {context} {notification_type} has failed because the patch coverage is below the target coverage. " | ||
"You can increase the patch coverage or adjust the " | ||
"[target](https://docs.codecov.com/docs/commit-status#target) coverage." | ||
) | ||
|
||
|
||
HELPER_TEXT_MAP = { | ||
CUSTOM_TARGET_TEXT_PATCH_KEY: CUSTOM_TARGET_TEXT_VALUE, | ||
CUSTOM_TARGET_TEXT_PROJECT_KEY: CUSTOM_TARGET_TEXT_VALUE, | ||
} | ||
|
||
|
||
class StatusPatchMixin(object): | ||
context = "patch" | ||
|
||
def _get_threshold(self) -> Decimal: | ||
""" | ||
Threshold can be configured by user, default is 0.0 | ||
|
@@ -29,7 +58,7 @@ def _get_threshold(self) -> Decimal: | |
|
||
def _get_target( | ||
self, comparison: ComparisonProxy | FilteredComparison | ||
) -> Decimal | None: | ||
) -> tuple[Decimal | None, bool]: | ||
""" | ||
Target can be configured by user, default is auto, which is the coverage level from the base report. | ||
Target will be None if no report is found to compare against. | ||
|
@@ -39,21 +68,24 @@ def _get_target( | |
target_coverage = Decimal( | ||
str(self.notifier_yaml_settings.get("target")).replace("%", "") | ||
) | ||
is_custom_target = True | ||
else: | ||
target_coverage = ( | ||
Decimal(comparison.project_coverage_base.report.totals.coverage) | ||
if comparison.has_project_coverage_base_report() | ||
and comparison.project_coverage_base.report.totals.coverage is not None | ||
else None | ||
) | ||
return target_coverage | ||
is_custom_target = False | ||
return target_coverage, is_custom_target | ||
|
||
def get_patch_status( | ||
self, comparison: ComparisonProxy | FilteredComparison | ||
) -> tuple[str, str]: | ||
self, comparison: ComparisonProxy | FilteredComparison, notification_type: str | ||
) -> StatusResult: | ||
threshold = self._get_threshold() | ||
target_coverage = self._get_target(comparison) | ||
target_coverage, is_custom_target = self._get_target(comparison) | ||
totals = comparison.get_patch_totals() | ||
included_helper_text = {} | ||
|
||
# coverage affected | ||
if totals and totals.lines > 0: | ||
|
@@ -84,7 +116,16 @@ def get_patch_status( | |
message = ( | ||
f"{coverage_rounded}% of diff hit (target {target_rounded}%)" | ||
) | ||
return state, message | ||
# TODO: | ||
# if state == StatusState.failure.value and is_custom_target: | ||
# helper_text = HELPER_TEXT_MAP[CUSTOM_TARGET_TEXT_PATCH_KEY].format( | ||
# context=self.context, notification_type=notification_type | ||
# ) | ||
# included_helper_text[CUSTOM_TARGET_TEXT_PATCH_KEY] = helper_text | ||
# message = message + " - " + helper_text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also decided I'm not going to add the helper text to this message, so the resulting message for check or status will be unchanged |
||
return StatusResult( | ||
state=state, message=message, included_helper_text=included_helper_text | ||
) | ||
|
||
# coverage not affected | ||
if comparison.project_coverage_base.commit: | ||
|
@@ -94,10 +135,16 @@ def get_patch_status( | |
) | ||
else: | ||
description = "Coverage not affected" | ||
return StatusState.success.value, description | ||
return StatusResult( | ||
state=StatusState.success.value, | ||
message=description, | ||
included_helper_text=included_helper_text, | ||
) | ||
|
||
|
||
class StatusChangesMixin(object): | ||
context = "changes" | ||
|
||
def is_a_change_worth_noting(self, change) -> bool: | ||
if not change.new and not change.deleted: | ||
# has totals and not -10m => 10h | ||
|
@@ -144,6 +191,7 @@ def get_changes_status( | |
|
||
class StatusProjectMixin(object): | ||
DEFAULT_REMOVED_CODE_BEHAVIOR = "adjust_base" | ||
context = "project" | ||
|
||
def _apply_removals_only_behavior( | ||
self, comparison: ComparisonProxy | FilteredComparison | ||
|
@@ -420,6 +468,11 @@ def _get_project_status( | |
# use rounded numbers for messages | ||
target_rounded = round_number(self.current_yaml, target_coverage) | ||
message = f"{head_coverage_rounded}% (target {target_rounded}%)" | ||
# TODO: | ||
# helper_text = HELPER_TEXT_MAP[CUSTOM_TARGET_TEXT].format( | ||
# context=self.context, notification_type=notification_type) | ||
# included_helper_text[CUSTOM_TARGET_TEXT] = helper_text | ||
# message = message + " - " + helper_text | ||
return state, message | ||
|
||
# use rounded numbers for messages | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also looking at the mockup for this, is it reasonable to include the numbers in this message as well, like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not in the design, but I think it makes sense - having the %s makes the message better, will add