Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display a message as to who archived a channel when using the close incident command #438

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/modules/incident/incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ def close_incident(client, body, ack):
# get the current chanel id and name
channel_id = body["channel_id"]
channel_name = body["channel_name"]
user_id = body["user_id"]

if not channel_name.startswith("incident-"):
user_id = body["user_id"]
try:
response = client.chat_postEphemeral(
text=f"Channel {channel_name} is not an incident channel. Please use this command in an incident channel.",
Expand Down Expand Up @@ -352,6 +352,12 @@ def close_incident(client, body, ack):
logging.error(
"Could not archive the channel %s - %s", channel_name, response["error"]
)
else:
# post a message that the channel has been archived by the user
client.chat_postMessage(
channel=channel_id,
text=f"<@{user_id}> has archived this channel 👋",
)


def stale_incidents(client, body, ack):
Expand Down
76 changes: 71 additions & 5 deletions app/tests/modules/incident/test_incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,11 @@ def test_close_incident(mock_extract_id, mock_update_spreadsheet, mock_close_doc
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -479,7 +483,11 @@ def test_close_incident_no_bookmarks(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -508,7 +516,11 @@ def test_close_incident_no_bookmarks_error(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -622,7 +634,11 @@ def test_conversations_archive_fail(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand Down Expand Up @@ -669,7 +685,11 @@ def test_conversations_archive_fail_error_message(
# Call close_incident
incident_helper.close_incident(
mock_client,
{"channel_id": "C12345", "channel_name": "incident-2024-01-12-test"},
{
"channel_id": "C12345",
"channel_name": "incident-2024-01-12-test",
"user_id": "U12345",
},
mock_ack,
)

Expand All @@ -687,6 +707,52 @@ def test_conversations_archive_fail_error_message(
)


@patch("modules.incident.incident_helper.google_drive.close_incident_document")
@patch(
"modules.incident.incident_helper.google_drive.update_spreadsheet_close_incident"
)
@patch(
"integrations.google_workspace.google_docs.extract_google_doc_id",
return_value="dummy_document_id",
)
def test_conversations_archive_succeeds_post_message_who_archived(
mock_extract_id, mock_update_spreadsheet, mock_close_document, caplog
):
mock_client = MagicMock()
mock_ack = MagicMock()
body = {
"channel_id": "channel_id",
"channel_name": "incident-channel_name",
"user_id": "user_id",
}
incident_helper.close_incident(mock_client, body, mock_ack)

# Mock the response of client.bookmarks_list with a valid bookmark
mock_client.bookmarks_list.return_value = {
"ok": True,
"bookmarks": [
{
"title": "Incident report",
"link": "https://docs.google.com/document/d/dummy_document_id/edit",
}
],
}

# Mock the response of client.conversations_archive to indicate success
mock_client.conversations_archive.return_value = {
"ok": True,
}

# assert that the channel was archived
mock_client.conversations_archive.assert_called_once_with(channel="channel_id")

# assert message was posted to archived channel.
mock_client.chat_postMessage.assert_any_call(
text="<@user_id> has archived this channel 👋",
channel="channel_id",
)


def test_return_channel_name_with_prefix():
# Test the function with a string that includes the prefix.
assert incident_helper.return_channel_name("incident-abc123") == "#abc123"
Expand Down
Loading