-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
🔧 chore(aci): Add support to invoke rule registry email handler from NOA #85130
Draft
iamrajjoshi
wants to merge
2
commits into
raj/invoke-rule-registry-rest-of-ticketing
Choose a base branch
from
raj/invoke-rule-registry-email
base: raj/invoke-rule-registry-rest-of-ticketing
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.
+245
−66
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 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 |
---|---|---|
|
@@ -7,13 +7,15 @@ | |
from sentry.models.rule import Rule, RuleSource | ||
from sentry.testutils.helpers.data_blobs import ( | ||
AZURE_DEVOPS_ACTION_DATA_BLOBS, | ||
EMAIL_ACTION_DATA_BLOBS, | ||
GITHUB_ACTION_DATA_BLOBS, | ||
JIRA_ACTION_DATA_BLOBS, | ||
JIRA_SERVER_ACTION_DATA_BLOBS, | ||
) | ||
from sentry.workflow_engine.handlers.action.notification.issue_alert import ( | ||
BaseIssueAlertHandler, | ||
DiscordIssueAlertHandler, | ||
EmailIssueAlertHandler, | ||
MSTeamsIssueAlertHandler, | ||
OpsgenieIssueAlertHandler, | ||
PagerDutyIssueAlertHandler, | ||
|
@@ -27,6 +29,7 @@ | |
EXCLUDED_ACTION_DATA_KEYS, | ||
ActionFieldMapping, | ||
ActionFieldMappingKeys, | ||
EmailActionHelper, | ||
) | ||
from tests.sentry.workflow_engine.test_base import BaseWorkflowTest | ||
|
||
|
@@ -353,17 +356,24 @@ def _test_build_rule_action_blob(self, expected, action_type: Action.Type): | |
) | ||
blob = self.handler.build_rule_action_blob(action) | ||
|
||
# pop uuid from blob | ||
# (we don't store it anymore since its a legacy artifact when we didn't have the action model) | ||
expected.pop("uuid") | ||
|
||
assert blob == { | ||
"id": expected["id"], | ||
"integration": expected["integration"], | ||
**blob, | ||
**expected, | ||
} | ||
|
||
|
||
class TestGithubIssueAlertHandler(TestTicketingIssueAlertHandlerBase): | ||
def test_build_rule_action_blob(self): | ||
for expected in GITHUB_ACTION_DATA_BLOBS: | ||
self._test_build_rule_action_blob(expected, Action.Type.GITHUB) | ||
if expected["id"] == ACTION_FIELD_MAPPINGS[Action.Type.GITHUB]["id"]: | ||
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. something else found with test updates. we have to do this since github/github enterprise config looks identical (based on code, currently there are no prod actions set up for ghe). |
||
self._test_build_rule_action_blob(expected, Action.Type.GITHUB) | ||
else: | ||
self._test_build_rule_action_blob(expected, Action.Type.GITHUB_ENTERPRISE) | ||
|
||
|
||
class TestAzureDevopsIssueAlertHandler(TestTicketingIssueAlertHandlerBase): | ||
|
@@ -382,3 +392,80 @@ class TestJiraServerIssueAlertHandler(TestTicketingIssueAlertHandlerBase): | |
def test_build_rule_action_blob(self): | ||
for expected in JIRA_SERVER_ACTION_DATA_BLOBS: | ||
self._test_build_rule_action_blob(expected, Action.Type.JIRA_SERVER) | ||
|
||
|
||
class TestEmailIssueAlertHandler(BaseWorkflowTest): | ||
def setUp(self): | ||
super().setUp() | ||
self.handler = EmailIssueAlertHandler() | ||
# These are the actions that are healed from the old email action data blobs | ||
# It removes targetIdentifier for IssueOwner targets (since that shouldn't be set for those) | ||
# It also removes the fallthroughType for Team and Member targets (since that shouldn't be set for those) | ||
self.HEALED_EMAIL_ACTION_DATA_BLOBS = [ | ||
# IssueOwners (targetIdentifier is "None") | ||
{ | ||
"targetType": "IssueOwners", | ||
"id": "sentry.mail.actions.NotifyEmailAction", | ||
"fallthroughType": "ActiveMembers", | ||
}, | ||
# NoOne Fallthrough (targetIdentifier is "") | ||
{ | ||
"targetType": "IssueOwners", | ||
"id": "sentry.mail.actions.NotifyEmailAction", | ||
"fallthroughType": "NoOne", | ||
}, | ||
# AllMembers Fallthrough (targetIdentifier is None) | ||
{ | ||
"targetType": "IssueOwners", | ||
"id": "sentry.mail.actions.NotifyEmailAction", | ||
"fallthroughType": "AllMembers", | ||
}, | ||
# NoOne Fallthrough (targetIdentifier is "None") | ||
{ | ||
"targetType": "IssueOwners", | ||
"id": "sentry.mail.actions.NotifyEmailAction", | ||
"fallthroughType": "NoOne", | ||
}, | ||
# ActiveMembers Fallthrough | ||
{ | ||
"targetType": "Member", | ||
"id": "sentry.mail.actions.NotifyEmailAction", | ||
"targetIdentifier": 3234013, | ||
}, | ||
# Member Email | ||
{ | ||
"id": "sentry.mail.actions.NotifyEmailAction", | ||
"targetIdentifier": 2160509, | ||
"targetType": "Member", | ||
}, | ||
# Team Email | ||
{ | ||
"targetType": "Team", | ||
"id": "sentry.mail.actions.NotifyEmailAction", | ||
"targetIdentifier": 188022, | ||
}, | ||
] | ||
|
||
def test_build_rule_action_blob(self): | ||
for expected, healed in zip(EMAIL_ACTION_DATA_BLOBS, self.HEALED_EMAIL_ACTION_DATA_BLOBS): | ||
action_data = pop_keys_from_data_blob(expected, Action.Type.EMAIL) | ||
|
||
# pop the targetType from the action_data | ||
target_type = EmailActionHelper.get_target_type_object(action_data.pop("targetType")) | ||
|
||
# Handle all possible targetIdentifier formats | ||
target_identifier = expected["targetIdentifier"] | ||
if target_identifier in ("None", "", None): | ||
target_identifier = None | ||
elif str(target_identifier).isnumeric(): | ||
target_identifier = int(target_identifier) | ||
|
||
action = self.create_action( | ||
type=Action.Type.EMAIL, | ||
data=action_data, | ||
target_type=target_type, | ||
target_identifier=target_identifier, | ||
) | ||
blob = self.handler.build_rule_action_blob(action) | ||
|
||
assert blob == healed |
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.
mistake found with test updates