diff --git a/app/jobs/notify_stale_incident_channels.py b/app/jobs/notify_stale_incident_channels.py index 1d9ca4ba..ef551a80 100644 --- a/app/jobs/notify_stale_incident_channels.py +++ b/app/jobs/notify_stale_incident_channels.py @@ -11,11 +11,11 @@ def notify_stale_incident_channels(client): channels = slack_channels.get_stale_channels( client, pattern=INCIDENT_CHANNELS_PATTERN ) - text = """👋 Hi! There have been no updates in this incident channel for 14 days! Consider archiving it.\n - Bonjour! Il n'y a pas eu de mise à jour dans ce canal d'incident depuis 14 jours. Vous pouvez considérer l'archiver.""" + text = """👋 Hi! There have been no updates in this incident channel for 14 days! Consider scheduling a retro or archiving it.\n + Bonjour! Il n'y a pas eu de mise à jour dans ce canal d'incident depuis 14 jours. Pensez à planifier une rétro ou à l'archiver.""" attachments = [ { - "text": "Would you like to archive the channel now? | Voulez-vous archiver ce canal maintenant?", + "text": "Would you like to archive the channel now or schedule a retro? | Souhaitez-vous archiver le canal maintenant ou planifier une rétro?", "fallback": "You are unable to archive the channel | Vous ne pouvez pas archiver ce canal", "callback_id": "archive_channel", "color": "#3AA3E3", @@ -23,14 +23,21 @@ def notify_stale_incident_channels(client): "actions": [ { "name": "archive", - "text": "Yes | Oui", + "text": "Archive channel | Canal d'archives", "type": "button", "value": "archive", "style": "danger", }, + { + "name": "schedule_retro", + "text": "Schedule Retro | Calendrier rétro", + "type": "button", + "value": "schedule_retro", + "style": "primary", + }, { "name": "ignore", - "text": "No | Non", + "text": "Ignore | Ignorer", "type": "button", "value": "ignore", }, diff --git a/app/modules/incident/incident_helper.py b/app/modules/incident/incident_helper.py index 9dfdba49..723e4b8e 100644 --- a/app/modules/incident/incident_helper.py +++ b/app/modules/incident/incident_helper.py @@ -129,24 +129,34 @@ def archive_channel_action(client, body, ack): ack() channel_id = body["channel"]["id"] action = body["actions"][0]["value"] + channel_name = body["channel"]["name"] user = body["user"]["id"] + + # get the current chanel id and name and make up the body with those 2 values + channel_info = { + "channel_id": channel_id, + "channel_name": channel_name, + "user_id": user, + } + if action == "ignore": - msg = f"<@{user}> has delayed archiving this channel for 14 days." + msg = ( + f"<@{user}> has delayed scheduling and archiving this channel for 14 days." + ) client.chat_update( channel=channel_id, text=msg, ts=body["message_ts"], attachments=[] ) log_to_sentinel("incident_channel_archive_delayed", body) elif action == "archive": - # get the current chanel id and name and make up the body with those 2 values - channel_info = { - "channel_id": channel_id, - "channel_name": body["channel"]["name"], - "user_id": user, - } # Call the close_incident function to update the incident document to closed, update the spreadsheet and archive the channel close_incident(client, channel_info, ack) # log the event to sentinel log_to_sentinel("incident_channel_archived", body) + elif action == "schedule_retro": + channel_info["trigger_id"] = body["trigger_id"] + schedule_incident_retro(client, channel_info, ack) + # log the event to sentinel + log_to_sentinel("incident_retro_scheduled", body) def delete_folder_metadata(client, body, ack): diff --git a/app/tests/jobs/test_notify_stale_incident_channels.py b/app/tests/jobs/test_notify_stale_incident_channels.py index 656118bc..65a6ef13 100644 --- a/app/tests/jobs/test_notify_stale_incident_channels.py +++ b/app/tests/jobs/test_notify_stale_incident_channels.py @@ -11,10 +11,10 @@ def test_notify_stale_incident_channels(_log_to_sentinel_mock, get_stale_channel notify_stale_incident_channels.notify_stale_incident_channels(client) client.chat_postMessage.assert_called_once_with( channel="channel_id", - text="👋 Hi! There have been no updates in this incident channel for 14 days! Consider archiving it.\n\n Bonjour! Il n'y a pas eu de mise à jour dans ce canal d'incident depuis 14 jours. Vous pouvez considérer l'archiver.", + text="👋 Hi! There have been no updates in this incident channel for 14 days! Consider scheduling a retro or archiving it.\n\n Bonjour! Il n'y a pas eu de mise à jour dans ce canal d'incident depuis 14 jours. Pensez à planifier une rétro ou à l'archiver.", attachments=[ { - "text": "Would you like to archive the channel now? | Voulez-vous archiver ce canal maintenant?", + "text": "Would you like to archive the channel now or schedule a retro? | Souhaitez-vous archiver le canal maintenant ou planifier une rétro?", "fallback": "You are unable to archive the channel | Vous ne pouvez pas archiver ce canal", "callback_id": "archive_channel", "color": "#3AA3E3", @@ -22,14 +22,21 @@ def test_notify_stale_incident_channels(_log_to_sentinel_mock, get_stale_channel "actions": [ { "name": "archive", - "text": "Yes | Oui", + "text": "Archive channel | Canal d'archives", "type": "button", "value": "archive", "style": "danger", }, + { + "name": "schedule_retro", + "text": "Schedule Retro | Calendrier rétro", + "type": "button", + "value": "schedule_retro", + "style": "primary", + }, { "name": "ignore", - "text": "No | Non", + "text": "Ignore | Ignorer", "type": "button", "value": "ignore", }, diff --git a/app/tests/modules/incident/test_incident_helper.py b/app/tests/modules/incident/test_incident_helper.py index 984fce41..a5ffde4e 100644 --- a/app/tests/modules/incident/test_incident_helper.py +++ b/app/tests/modules/incident/test_incident_helper.py @@ -93,7 +93,7 @@ def test_archive_channel_action_ignore(mock_log_to_sentinel): client = MagicMock() body = { "actions": [{"value": "ignore"}], - "channel": {"id": "channel_id"}, + "channel": {"id": "channel_id", "name": "incident-2024-01-12-test"}, "message_ts": "message_ts", "user": {"id": "user_id"}, } @@ -136,6 +136,20 @@ def test_archive_channel_action_archive( mock_log_to_sentinel.assert_called_once_with("incident_channel_archived", body) +@patch("modules.incident.incident_helper.log_to_sentinel") +def test_archive_channel_action_schedule_incident(mock_log_to_sentinel): + client = MagicMock() + channel_info = { + "channel_id": "channel_id", + "channel_name": "channel_name", + "channel": {"id": "channel_id", "name": "incident-2024-01-12-test"}, + "user_id": "user_id", + } + ack = MagicMock() + incident_helper.schedule_incident_retro(client, channel_info, ack) + assert ack.call_count == 1 + + @patch("modules.incident.incident_helper.google_drive.delete_metadata") @patch("modules.incident.incident_helper.view_folder_metadata") def test_delete_folder_metadata(view_folder_metadata_mock, delete_metadata_mock):