-
Notifications
You must be signed in to change notification settings - Fork 8
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
Logic to remove checks from team plan customer #463
Changes from 2 commits
76c902d
d6791e8
c5adbb8
972c3c9
1673479
e8ba0de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,10 @@ | |
from celery.exceptions import CeleryError, SoftTimeLimitExceeded | ||
from shared.config import get_config | ||
from shared.helpers.yaml import default_if_true | ||
from shared.plan.constants import TEAM_PLAN_REPRESENTATIONS | ||
from shared.yaml import UserYaml | ||
|
||
from database.models.core import GITHUB_APP_INSTALLATION_DEFAULT_NAME | ||
from database.models.core import GITHUB_APP_INSTALLATION_DEFAULT_NAME, Owner | ||
from helpers.metrics import metrics | ||
from services.comparison import ComparisonProxy | ||
from services.decoration import Decoration | ||
|
@@ -24,6 +25,7 @@ | |
create_or_update_commit_notification_from_notification_result, | ||
) | ||
from services.notification.notifiers import ( | ||
StatusType, | ||
get_all_notifier_classes_mapping, | ||
get_pull_request_notifiers, | ||
get_status_notifier_class, | ||
|
@@ -55,15 +57,28 @@ | |
self.decoration_type = decoration_type | ||
self.gh_installation_name_to_use = gh_installation_name_to_use | ||
|
||
def _should_use_checks_notifier(self) -> bool: | ||
def _should_use_status_notifier(self, status_type: StatusType) -> bool: | ||
owner: Owner = self.repository.owner | ||
|
||
if owner.plan in TEAM_PLAN_REPRESENTATIONS: | ||
if status_type != StatusType.PATCH.value: | ||
return False | ||
|
||
return True | ||
|
||
def _should_use_checks_notifier(self, status_type: StatusType) -> bool: | ||
checks_yaml_field = read_yaml_field(self.current_yaml, ("github_checks",)) | ||
if checks_yaml_field is False: | ||
return False | ||
|
||
owner = self.repository.owner | ||
owner: Owner = self.repository.owner | ||
if owner.service not in ["github", "github_enterprise"]: | ||
return False | ||
|
||
if owner.plan in TEAM_PLAN_REPRESENTATIONS: | ||
if status_type != StatusType.PATCH.value: | ||
return False | ||
|
||
app_installation_filter = filter( | ||
lambda obj: ( | ||
obj.name == self.gh_installation_name_to_use and obj.is_configured() | ||
|
@@ -101,39 +116,52 @@ | |
|
||
current_flags = [rf.flag_name for rf in self.repository.flags if not rf.deleted] | ||
for key, title, status_config in self.get_statuses(current_flags): | ||
status_notifier_class = get_status_notifier_class(key, "status") | ||
if self._should_use_checks_notifier(): | ||
checks_notifier = get_status_notifier_class(key, "checks") | ||
yield ChecksWithFallback( | ||
checks_notifier=checks_notifier( | ||
repository=self.repository, | ||
title=title, | ||
notifier_yaml_settings=status_config, | ||
notifier_site_settings={}, | ||
current_yaml=self.current_yaml, | ||
decoration_type=self.decoration_type, | ||
gh_installation_name_to_use=self.gh_installation_name_to_use, | ||
), | ||
status_notifier=status_notifier_class( | ||
should_use_status_notifiers = self._should_use_status_notifier( | ||
status_type=key | ||
) | ||
should_use_checks_notifier = self._should_use_checks_notifier( | ||
status_type=key | ||
) | ||
|
||
# Introduced to gate team plan not having statuses nor checks based on conditionals. | ||
if not should_use_status_notifiers and not should_use_checks_notifier: | ||
continue | ||
Check warning on line 128 in services/notification/__init__.py Codecov Public QA / codecov/patchservices/notification/__init__.py#L128
Check warning on line 128 in services/notification/__init__.py Codecov - QA / codecov/patchservices/notification/__init__.py#L128
|
||
|
||
# We always send statuses, so there's currently no case of checks without status. | ||
if should_use_status_notifiers: | ||
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. for readability maybe the logic following here should be encapsulated in a function |
||
status_notifier_class = get_status_notifier_class(key, "status") | ||
if should_use_checks_notifier: | ||
checks_notifier = get_status_notifier_class(key, "checks") | ||
yield ChecksWithFallback( | ||
checks_notifier=checks_notifier( | ||
repository=self.repository, | ||
title=title, | ||
notifier_yaml_settings=status_config, | ||
notifier_site_settings={}, | ||
current_yaml=self.current_yaml, | ||
decoration_type=self.decoration_type, | ||
gh_installation_name_to_use=self.gh_installation_name_to_use, | ||
), | ||
status_notifier=status_notifier_class( | ||
repository=self.repository, | ||
title=title, | ||
notifier_yaml_settings=status_config, | ||
notifier_site_settings={}, | ||
current_yaml=self.current_yaml, | ||
decoration_type=self.decoration_type, | ||
gh_installation_name_to_use=self.gh_installation_name_to_use, | ||
), | ||
) | ||
else: | ||
yield status_notifier_class( | ||
repository=self.repository, | ||
title=title, | ||
notifier_yaml_settings=status_config, | ||
notifier_site_settings={}, | ||
current_yaml=self.current_yaml, | ||
decoration_type=self.decoration_type, | ||
gh_installation_name_to_use=self.gh_installation_name_to_use, | ||
), | ||
) | ||
else: | ||
yield status_notifier_class( | ||
repository=self.repository, | ||
title=title, | ||
notifier_yaml_settings=status_config, | ||
notifier_site_settings={}, | ||
current_yaml=self.current_yaml, | ||
decoration_type=self.decoration_type, | ||
gh_installation_name_to_use=self.gh_installation_name_to_use, | ||
) | ||
) | ||
|
||
# yield notifier if slack_app field is True, nonexistent, or a non-empty dict | ||
slack_app_yaml_field = read_yaml_field(self.current_yaml, ("slack_app",), True) | ||
|
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.
i'm wondering if this is meant to skip the comment and slack notifiers, if not, or if they will be skipped anyways, then we can remove this if statement
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.
We should have the comment, clarifying about the slack one, but how would removing this help?
To clarify the logic here, everything remains the same, the only change introduced by this ticket is "if you're in a team plan, and you have a "changes" or "project" status checks, we don't show them, we only show "patch" specific comments" (the ticket was originally "skip everything" but its now "skip some things". There was a fn
_should_use_checks_notifier
that has some logic in it already that decides whether you show checks or not - I added a small case inside to do the team plan changes. We also always sent statuses, which changes with this ticket, so I added a fn_should_use_status_notifier
which just adds the team plan related logic to it, otherwise returns true.So I don't see a way to get rid of this if ^ here.