Skip to content

Commit

Permalink
Adding initial files to change the notification for incidnet archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviamclaughlin authored Apr 11, 2024
1 parent 26d9c0e commit f421107
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
20 changes: 14 additions & 6 deletions app/jobs/notify_stale_incident_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,33 @@ 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 la chaîne maintenant ou programmer une rétro?",
"fallback": "You are unable to archive the channel | Vous ne pouvez pas archiver ce canal",
"callback_id": "archive_channel",
"color": "#3AA3E3",
"attachment_type": "default",
"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",
},
Expand All @@ -40,5 +47,6 @@ def notify_stale_incident_channels(client):
for channel in channels:
log_to_sentinel("sent_stale_channel_notification", {"channel": channel})
client.chat_postMessage(
channel=channel["id"], text=text, attachments=attachments
#channel=channel["id"], text=text, attachments=attachments
channel="C06TVP0V5AR", text=text, attachments=attachments
)
22 changes: 15 additions & 7 deletions app/modules/incident/incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,32 @@ 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,
"trigger_id": body["trigger_id"],
}

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":
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):
Expand Down
15 changes: 11 additions & 4 deletions app/tests/jobs/test_notify_stale_incident_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,32 @@ 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 la chaîne maintenant ou programmer une rétro?",
"fallback": "You are unable to archive the channel | Vous ne pouvez pas archiver ce canal",
"callback_id": "archive_channel",
"color": "#3AA3E3",
"attachment_type": "default",
"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": "archive",
"style": "primary",
},
{
"name": "ignore",
"text": "No | Non",
"text": "Ignore | Ignorer",
"type": "button",
"value": "ignore",
},
Expand Down
24 changes: 23 additions & 1 deletion app/tests/modules/incident/test_incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
Expand Down Expand Up @@ -136,6 +136,28 @@ 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()
body = {
"actions": [{"value": "schedule_retro"}],
"channel": {"id": "channel_id", "name": "incident-2024-01-12-test"},
"message_ts": "message_ts",
"user": {"id": "user_id"},
}
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):
Expand Down

0 comments on commit f421107

Please sign in to comment.