11from __future__ import annotations
22
33import logging
4- from collections .abc import Sequence
5- from typing import cast
4+ from collections .abc import Generator , Sequence
5+ from typing import Any , TypedDict , cast
66
77import sentry_sdk
88
1616from sentry .integrations .types import IntegrationProviderSlug
1717from sentry .models .rule import Rule
1818from sentry .rules .actions import IntegrationEventAction
19+ from sentry .rules .base import CallbackFuture
20+ from sentry .services .eventstore .models import GroupEvent
1921from sentry .shared_integrations .exceptions import ApiError
22+ from sentry .types .rules import RuleFuture
2023from sentry .utils .strings import truncatechars
2124
2225logger = logging .getLogger ("sentry.integrations.pagerduty" )
2326
2427
28+ class PagerDutyService (TypedDict ):
29+ id : int
30+ integration_key : str
31+ service_name : str
32+ integration_id : int
33+
34+
2535class PagerDutyNotifyServiceAction (IntegrationEventAction ):
2636 id = "sentry.integrations.pagerduty.notify_action.PagerDutyNotifyServiceAction"
2737 label = "Send a notification to PagerDuty account {account} and service {service} with {severity} severity"
2838 prompt = "Send a PagerDuty notification"
2939 provider = IntegrationProviderSlug .PAGERDUTY .value
3040 integration_key = "account"
3141
32- def __init__ (self , * args , ** kwargs ) :
42+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
3343 super ().__init__ (* args , ** kwargs )
3444 self .form_fields = {
3545 "account" : {
@@ -49,7 +59,7 @@ def __init__(self, *args, **kwargs):
4959 },
5060 }
5161
52- def _get_service (self ):
62+ def _get_service (self ) -> PagerDutyService | None :
5363 oi = self .get_organization_integration ()
5464 if not oi :
5565 return None
@@ -58,7 +68,9 @@ def _get_service(self):
5868 return pds
5969 return None
6070
61- def after (self , event , notification_uuid : str | None = None ):
71+ def after (
72+ self , event : GroupEvent , notification_uuid : str | None = None
73+ ) -> Generator [CallbackFuture ]:
6274 integration = self .get_integration ()
6375 log_context = {
6476 "organization_id" : self .project .organization_id ,
@@ -79,7 +91,7 @@ def after(self, event, notification_uuid: str | None = None):
7991 PagerdutySeverity , self .get_option ("severity" , default = PAGERDUTY_DEFAULT_SEVERITY )
8092 )
8193
82- def send_notification (event , futures ) :
94+ def send_notification (event : GroupEvent , futures : Sequence [ RuleFuture ]) -> None :
8395 installation = integration .get_installation (self .project .organization_id )
8496 try :
8597 client = installation .get_keyring_client (self .get_option ("service" ))
@@ -147,7 +159,7 @@ def get_services(self) -> Sequence[tuple[int, str]]:
147159 for v in oi .config .get ("pagerduty_services" , [])
148160 ]
149161
150- def render_label (self ):
162+ def render_label (self ) -> str :
151163 s = self ._get_service ()
152164 if s :
153165 service_name = s ["service_name" ]
0 commit comments