-
Notifications
You must be signed in to change notification settings - Fork 10
add force notify option #349
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
Draft
joseph-sentry
wants to merge
2
commits into
main
Choose a base branch
from
joseph/force-notify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -148,7 +148,18 @@ def notify( | |||||||||||||||||||||||
| comparison: ComparisonProxy, | ||||||||||||||||||||||||
| status_or_checks_helper_text: dict[str, str] | None = None, | ||||||||||||||||||||||||
| ) -> NotificationResult: | ||||||||||||||||||||||||
| payload = None | ||||||||||||||||||||||||
| force_notify = getattr(comparison.context, "force_notify", False) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if not force_notify: | ||||||||||||||||||||||||
| validation_result = self._perform_validation_checks(comparison) | ||||||||||||||||||||||||
| if validation_result: | ||||||||||||||||||||||||
| return validation_result | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return self._perform_notification(comparison) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def _perform_validation_checks( | ||||||||||||||||||||||||
| self, comparison: ComparisonProxy | ||||||||||||||||||||||||
| ) -> NotificationResult | None: | ||||||||||||||||||||||||
| if not self.can_we_set_this_status(comparison): | ||||||||||||||||||||||||
| return NotificationResult( | ||||||||||||||||||||||||
| notification_attempted=False, | ||||||||||||||||||||||||
|
|
@@ -163,6 +174,28 @@ def notify( | |||||||||||||||||||||||
| explanation="need_more_builds", | ||||||||||||||||||||||||
| data_sent=None, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Check flag coverage behavior when force_notify is False | ||||||||||||||||||||||||
| flag_coverage_not_uploaded_behavior = ( | ||||||||||||||||||||||||
| self.determine_status_check_behavior_to_apply( | ||||||||||||||||||||||||
| comparison, "flag_coverage_not_uploaded_behavior" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||
| flag_coverage_not_uploaded_behavior == "exclude" | ||||||||||||||||||||||||
| and not self.flag_coverage_was_uploaded(comparison) | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| return NotificationResult( | ||||||||||||||||||||||||
| notification_attempted=False, | ||||||||||||||||||||||||
| notification_successful=None, | ||||||||||||||||||||||||
| explanation="exclude_flag_coverage_not_uploaded_checks", | ||||||||||||||||||||||||
| data_sent=None, | ||||||||||||||||||||||||
| data_received=None, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def _perform_notification(self, comparison: ComparisonProxy) -> NotificationResult: | ||||||||||||||||||||||||
| # Filter the coverage report based on fields in this notification's YAML settings | ||||||||||||||||||||||||
| # e.g. if "paths" is specified, exclude the coverage not on those paths | ||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||
|
|
@@ -174,17 +207,6 @@ def notify( | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| if not comparison.has_head_report(): | ||||||||||||||||||||||||
| payload = self.build_payload(comparison) | ||||||||||||||||||||||||
| elif ( | ||||||||||||||||||||||||
| flag_coverage_not_uploaded_behavior == "exclude" | ||||||||||||||||||||||||
| and not self.flag_coverage_was_uploaded(comparison) | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| return NotificationResult( | ||||||||||||||||||||||||
| notification_attempted=False, | ||||||||||||||||||||||||
| notification_successful=None, | ||||||||||||||||||||||||
| explanation="exclude_flag_coverage_not_uploaded_checks", | ||||||||||||||||||||||||
| data_sent=None, | ||||||||||||||||||||||||
| data_received=None, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| elif ( | ||||||||||||||||||||||||
| flag_coverage_not_uploaded_behavior == "pass" | ||||||||||||||||||||||||
| and not self.flag_coverage_was_uploaded(comparison) | ||||||||||||||||||||||||
|
|
@@ -262,6 +284,11 @@ def get_status_external_name(self) -> str: | |||||||||||||||||||||||
| def maybe_send_notification( | ||||||||||||||||||||||||
| self, comparison: ComparisonProxy, payload: dict | ||||||||||||||||||||||||
| ) -> NotificationResult: | ||||||||||||||||||||||||
| force_notify = getattr(comparison.context, "force_notify", False) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if force_notify: | ||||||||||||||||||||||||
| return self.send_notification(comparison, payload) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| base_commit = ( | ||||||||||||||||||||||||
| comparison.project_coverage_base.commit | ||||||||||||||||||||||||
| if comparison.project_coverage_base | ||||||||||||||||||||||||
|
|
@@ -306,14 +333,19 @@ def maybe_send_notification( | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def send_notification(self, comparison: ComparisonProxy, payload): | ||||||||||||||||||||||||
| force_notify = getattr(comparison.context, "force_notify", False) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| repository_service = self.repository_service | ||||||||||||||||||||||||
| title = self.get_status_external_name() | ||||||||||||||||||||||||
| head_commit_sha = comparison.head.commit.commitid | ||||||||||||||||||||||||
| head_report = comparison.head.report | ||||||||||||||||||||||||
| state = payload["state"] | ||||||||||||||||||||||||
| message = payload["message"] | ||||||||||||||||||||||||
| url = payload["url"] | ||||||||||||||||||||||||
| if self.status_already_exists(comparison, title, state, message): | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+336
to
+345
Contributor
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. The logic for handling
Suggested change
Did we get this right? 👍 / 👎 to inform future reviews. |
||||||||||||||||||||||||
| if not force_notify and self.status_already_exists( | ||||||||||||||||||||||||
| comparison, title, state, message | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| log.info( | ||||||||||||||||||||||||
| "Status already set", | ||||||||||||||||||||||||
| extra={"context": title, "description": message, "state": state}, | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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.
Potential bug: Bypassing `comparison.pull` and `comparison.enriched_pull.provider_pull` validation in the comment notifier with `force_notify=True` can cause `AttributeError` when accessing their attributes, leading to crashes.
ComparisonHasPull(ensuringcomparison.pull is not None) andPullRequestInProvider(ensuringcomparison.enriched_pull.provider_pull is not None). This allows execution to reachbuild_message()(e.g., line 427) wherecomparison.pull.is_first_coverage_pullis accessed, orcomparison.enriched_pull.provider_pull(line 428) is accessed directly. Similarly,pull.pullid(line 134) andcomparison.enriched_pull.provider_pull["author"]in_create_upgrade_message()are accessed without null checks. If the bypassed objects areNone, these accesses will raise anAttributeError(e.g.,'NoneType' object has no attribute 'is_first_coverage_pull'), leading to an unhandled exception and a crash in the notification process.ComparisonHasPullandPullRequestInProvidervalidations in the comment notifier whenforce_notify=True, or add explicit null checks forcomparison.pullandcomparison.enriched_pull.provider_pullbefore accessing their attributes.severity: 0.9, confidence: 0.95
Did we get this right? 👍 / 👎 to inform future reviews.