From 8f3331c7c00569e8563d65619a8c77402b323c11 Mon Sep 17 00:00:00 2001 From: Will Sheldon Date: Tue, 20 May 2025 15:22:17 -0700 Subject: [PATCH 1/5] fix: slack plugin activity fetch --- src/dispatch/plugins/dispatch_slack/plugin.py | 41 +++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/src/dispatch/plugins/dispatch_slack/plugin.py b/src/dispatch/plugins/dispatch_slack/plugin.py index 9575a61e8db4..c2628ea02a90 100644 --- a/src/dispatch/plugins/dispatch_slack/plugin.py +++ b/src/dispatch/plugins/dispatch_slack/plugin.py @@ -416,28 +416,17 @@ def get_command_name(self, command: str): return command_mappings.get(command, []) def fetch_events( - self, - db_session: Session, - subject: Any, - plugin_event_id: int, - oldest: str = "0", - **kwargs, + self, db_session: Session, subject: Any, plugin_event_id: int, oldest: str = "0", **kwargs ): - """ - Fetches incident events from the Slack plugin. + """Fetches incident events from the Slack plugin. Args: - db_session (Session): The database session. - subject (Any): The subject of the event, e.g., an Incident or Case object. - plugin_event_id (int): The plugin event ID. - oldest (str, optional): The oldest timestamp to fetch events from. Defaults to "0". - **kwargs: Additional keyword arguments. + subject: An Incident or Case object. + plugin_event_id: The plugin event id. + oldest: The oldest timestamp to fetch events from. Returns: - list[tuple]: A sorted list of tuples (utc_dt, user_id). - - Raises: - Exception: If there is an error fetching events from Slack. + A sorted list of tuples (utc_dt, user_id). """ try: client = create_slack_client(self.configuration) @@ -445,19 +434,11 @@ def fetch_events( db_session=db_session, plugin_event_id=plugin_event_id ) event = self.get_event(plugin_event) - if event is None: - raise ValueError(f"No event found for Slack plugin event: {plugin_event}") - if isinstance(event, type): - # It's a class, instantiate it - event = event(plugin_event) - return event.fetch_activity( - client=client, - subject=subject, - oldest=oldest, - ) - except Exception: - logger.exception("Error fetching events from Slack") - raise + activity = event.fetch_activity(client, subject, oldest) + return activity + except Exception as e: + logger.exception(e) + raise e def get_conversation_replies(self, conversation_id: str, thread_ts: str) -> list[str]: """ From c1a24bf169c1b15f8404575dc9cc4d64d5e2c6e2 Mon Sep 17 00:00:00 2001 From: Will Sheldon Date: Tue, 20 May 2025 15:23:17 -0700 Subject: [PATCH 2/5] chore: check if event is none --- src/dispatch/plugins/dispatch_slack/plugin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dispatch/plugins/dispatch_slack/plugin.py b/src/dispatch/plugins/dispatch_slack/plugin.py index c2628ea02a90..3b9a06644603 100644 --- a/src/dispatch/plugins/dispatch_slack/plugin.py +++ b/src/dispatch/plugins/dispatch_slack/plugin.py @@ -434,6 +434,8 @@ def fetch_events( db_session=db_session, plugin_event_id=plugin_event_id ) event = self.get_event(plugin_event) + if event is None: + raise ValueError(f"No event found for Slack plugin event: {plugin_event}") activity = event.fetch_activity(client, subject, oldest) return activity except Exception as e: From 3fa5970fbc29487b604d08e8661ef522b99ff0e1 Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Tue, 20 May 2025 15:23:55 -0700 Subject: [PATCH 3/5] chore: update logger exception Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Will Sheldon <114631109+wssheldon@users.noreply.github.com> --- src/dispatch/plugins/dispatch_slack/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dispatch/plugins/dispatch_slack/plugin.py b/src/dispatch/plugins/dispatch_slack/plugin.py index 3b9a06644603..2104293bd8a4 100644 --- a/src/dispatch/plugins/dispatch_slack/plugin.py +++ b/src/dispatch/plugins/dispatch_slack/plugin.py @@ -439,8 +439,8 @@ def fetch_events( activity = event.fetch_activity(client, subject, oldest) return activity except Exception as e: - logger.exception(e) - raise e + logger.exception("An error occurred while fetching incident events from the Slack plugin.", exc_info=e) + raise def get_conversation_replies(self, conversation_id: str, thread_ts: str) -> list[str]: """ From acb7adbac7f2ec0a52636ea2d0191a98ebd85cbe Mon Sep 17 00:00:00 2001 From: Will Sheldon Date: Tue, 20 May 2025 16:02:22 -0700 Subject: [PATCH 4/5] fix: instantiate event --- src/dispatch/plugins/dispatch_slack/plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dispatch/plugins/dispatch_slack/plugin.py b/src/dispatch/plugins/dispatch_slack/plugin.py index 2104293bd8a4..4458afdae7f2 100644 --- a/src/dispatch/plugins/dispatch_slack/plugin.py +++ b/src/dispatch/plugins/dispatch_slack/plugin.py @@ -436,7 +436,9 @@ def fetch_events( event = self.get_event(plugin_event) if event is None: raise ValueError(f"No event found for Slack plugin event: {plugin_event}") - activity = event.fetch_activity(client, subject, oldest) + + event_instance = event() + activity = event_instance.fetch_activity(client, subject, oldest) return activity except Exception as e: logger.exception("An error occurred while fetching incident events from the Slack plugin.", exc_info=e) From 348b1c24dd7cdcbd8e68ec1c360f0ba1cb86d642 Mon Sep 17 00:00:00 2001 From: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Date: Tue, 20 May 2025 16:03:06 -0700 Subject: [PATCH 5/5] chore: err msg Co-authored-by: Marc Vilanova <39573146+mvilanova@users.noreply.github.com> Signed-off-by: Will Sheldon <114631109+wssheldon@users.noreply.github.com> --- src/dispatch/plugins/dispatch_slack/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatch/plugins/dispatch_slack/plugin.py b/src/dispatch/plugins/dispatch_slack/plugin.py index 4458afdae7f2..f457674129f0 100644 --- a/src/dispatch/plugins/dispatch_slack/plugin.py +++ b/src/dispatch/plugins/dispatch_slack/plugin.py @@ -441,7 +441,7 @@ def fetch_events( activity = event_instance.fetch_activity(client, subject, oldest) return activity except Exception as e: - logger.exception("An error occurred while fetching incident events from the Slack plugin.", exc_info=e) + logger.exception("An error occurred while fetching incident or case events from the Slack plugin.", exc_info=e) raise def get_conversation_replies(self, conversation_id: str, thread_ts: str) -> list[str]: