Skip to content

Commit b4b811a

Browse files
committed
test changes
1 parent a5b1c3f commit b4b811a

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

src/sentry/workflow_engine/migrations/0038_migrate_metric_alerts.py

+39-10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ class AlertRuleActivityType(Enum):
7373
DEACTIVATED = 8
7474

7575

76+
class ActionTarget(IntEnum):
77+
"""
78+
Explains the contents of target_identifier
79+
"""
80+
81+
# The target_identifier is a direct reference used by the service (e.g. email address, slack channel id)
82+
SPECIFIC = 0
83+
# The target_identifier is an id from the User model in Sentry
84+
USER = 1
85+
# The target_identifier is an id from the Team model in Sentry
86+
TEAM = 2
87+
# The target_identifier is an id from the SentryApp model in Sentry
88+
SENTRY_APP = 3
89+
# There is no target_identifier, but we want to send notifications to the issue owners
90+
ISSUE_OWNERS = 4
91+
92+
7693
class ActionType(StrEnum):
7794
SLACK = "slack"
7895
MSTEAMS = "msteams"
@@ -94,6 +111,16 @@ class ActionType(StrEnum):
94111
WEBHOOK = "webhook"
95112

96113

114+
class SentryAppIdentifier(StrEnum):
115+
"""
116+
SentryAppIdentifier is an enum that represents the identifier for a Sentry app.
117+
"""
118+
119+
SENTRY_APP_INSTALLATION_UUID = "sentry_app_installation_uuid"
120+
SENTRY_APP_SLUG = "sentry_app_slug"
121+
SENTRY_APP_ID = "sentry_app_id"
122+
123+
97124
FIELDS_TO_DETECTOR_FIELDS = {
98125
"name": "name",
99126
"description": "description",
@@ -249,11 +276,7 @@ def _migrate_trigger_action(apps: Apps, trigger_action: Any, condition_group_id:
249276
priority = config.get("priority", default_priority)
250277
data = dataclasses.asdict(OnCallDataBlob(priority=priority))
251278
else:
252-
data = {
253-
"type": trigger_action.type,
254-
"sentry_app_id": trigger_action.sentry_app_id,
255-
"sentry_app_config": trigger_action.sentry_app_config,
256-
}
279+
data = {}
257280

258281
# get target identifier
259282
if action_type == ActionType.SENTRY_APP:
@@ -267,16 +290,22 @@ def _migrate_trigger_action(apps: Apps, trigger_action: Any, condition_group_id:
267290
else:
268291
target_identifier = trigger_action.target_identifier
269292

293+
# build config
294+
target_type = trigger_action.target_type
295+
config = {
296+
"target_display": trigger_action.target_display,
297+
"target_identifier": target_identifier,
298+
"target_type": target_type,
299+
}
300+
if target_type == ActionTarget.SENTRY_APP.value:
301+
config["sentry_app_identifier"] = SentryAppIdentifier.SENTRY_APP_ID
302+
270303
# create the models
271304
action = Action.objects.create(
272305
type=action_type,
273306
data=data,
274307
integration_id=trigger_action.integration_id,
275-
config={
276-
"target_display": trigger_action.target_display,
277-
"target_identifier": target_identifier,
278-
"target_type": trigger_action.target_type,
279-
},
308+
config=config,
280309
)
281310
DataConditionGroupAction.objects.create(
282311
condition_group_id=condition_group_id,

tests/sentry/workflow_engine/migrations/test_0038_migrate_metric_alerts.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,7 @@ def test_simple_trigger_action(self):
345345
action=action.id,
346346
)
347347
assert action.type == Action.Type.EMAIL
348-
assert action.data == {
349-
"type": self.email_action.type,
350-
"sentry_app_id": self.email_action.sentry_app_id,
351-
"sentry_app_config": self.email_action.sentry_app_config,
352-
}
348+
assert action.data == {}
353349
assert action.integration_id is None
354350
assert action.config.get("target_display") is None
355351
assert action.config.get("target_identifier") == self.email_action.target_identifier
@@ -410,6 +406,7 @@ def test_sentry_app_trigger_action(self):
410406
assert action.config.get("target_display") == self.sentry_app_action.target_display
411407
assert action.config.get("target_identifier") == self.sentry_app_action.target_identifier
412408
assert action.config.get("target_type") == self.sentry_app_action.target_type
409+
assert action.config.get("sentry_app_identifier") == "sentry_app_id"
413410

414411
def test_skip_dynamic_rule(self):
415412
assert not AlertRuleDetector.objects.filter(alert_rule=self.dynamic_rule).exists()

0 commit comments

Comments
 (0)