@@ -73,6 +73,23 @@ class AlertRuleActivityType(Enum):
73
73
DEACTIVATED = 8
74
74
75
75
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
+
76
93
class ActionType (StrEnum ):
77
94
SLACK = "slack"
78
95
MSTEAMS = "msteams"
@@ -94,6 +111,16 @@ class ActionType(StrEnum):
94
111
WEBHOOK = "webhook"
95
112
96
113
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
+
97
124
FIELDS_TO_DETECTOR_FIELDS = {
98
125
"name" : "name" ,
99
126
"description" : "description" ,
@@ -249,11 +276,7 @@ def _migrate_trigger_action(apps: Apps, trigger_action: Any, condition_group_id:
249
276
priority = config .get ("priority" , default_priority )
250
277
data = dataclasses .asdict (OnCallDataBlob (priority = priority ))
251
278
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 = {}
257
280
258
281
# get target identifier
259
282
if action_type == ActionType .SENTRY_APP :
@@ -267,16 +290,22 @@ def _migrate_trigger_action(apps: Apps, trigger_action: Any, condition_group_id:
267
290
else :
268
291
target_identifier = trigger_action .target_identifier
269
292
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
+
270
303
# create the models
271
304
action = Action .objects .create (
272
305
type = action_type ,
273
306
data = data ,
274
307
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 ,
280
309
)
281
310
DataConditionGroupAction .objects .create (
282
311
condition_group_id = condition_group_id ,
0 commit comments