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

Improves list incidents Slack command #1225

Merged
merged 1 commit into from
May 25, 2021
Merged
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
79 changes: 45 additions & 34 deletions src/dispatch/plugins/dispatch_slack/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
from dispatch.enums import Visibility
from dispatch.incident import service as incident_service
from dispatch.incident.enums import IncidentStatus
from dispatch.incident.messaging import send_incident_resources_ephemeral_message_to_participant
from dispatch.participant import service as participant_service
from dispatch.participant_role import service as participant_role_service
from dispatch.participant_role.models import ParticipantRoleType
from dispatch.plugin import service as plugin_service
from dispatch.plugins.dispatch_slack import service as dispatch_slack_service
from dispatch.project import service as project_service
from dispatch.task import service as task_service
from dispatch.task.models import TaskStatus, Task


from dispatch.incident.messaging import send_incident_resources_ephemeral_message_to_participant

from .config import (
SLACK_APP_USER_SLUG,
SLACK_COMMAND_ADD_TIMELINE_EVENT_SLUG,
Expand All @@ -43,16 +42,6 @@

from .decorators import slack_background_task

from .modals.incident.handlers import (
create_add_timeline_event_modal,
create_report_incident_modal,
create_update_incident_modal,
create_update_notifications_group_modal,
create_update_participant_modal,
)

from .modals.workflow.handlers import create_run_workflow_modal

from .dialogs import (
create_assign_role_dialog,
create_engage_oncall_dialog,
Expand All @@ -67,6 +56,16 @@
create_command_run_by_non_privileged_user_message,
)

from .modals.incident.handlers import (
create_add_timeline_event_modal,
create_report_incident_modal,
create_update_incident_modal,
create_update_notifications_group_modal,
create_update_participant_modal,
)

from .modals.workflow.handlers import create_run_workflow_modal


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -477,39 +476,50 @@ def list_incidents(
):
"""Returns the list of current active and stable incidents,
and closed incidents in the last 24 hours."""
projects = []
incidents = []

# scopes reply to the current incident's project
incident = incident_service.get(db_session=db_session, incident_id=incident_id)

# We fetch active incidents
incidents = incident_service.get_all_by_status(
db_session=db_session, project_id=incident.project.id, status=IncidentStatus.active.value
)
# We fetch stable incidents
incidents.extend(
incident_service.get_all_by_status(
db_session=db_session,
project_id=incident.project.id,
status=IncidentStatus.stable.value,
if incident:
# command was run in an incident conversation
projects.append(incident.project)
else:
# command was run in a non-incident conversation
projects = project_service.get_all(db_session=db_session)

for project in projects:
# we fetch active incidents
incidents.extend(
incident_service.get_all_by_status(
db_session=db_session, project_id=project.id, status=IncidentStatus.active.value
)
)
)
# We fetch closed incidents in the last 24 hours
incidents.extend(
incident_service.get_all_last_x_hours_by_status(
db_session=db_session,
project_id=incident.project.id,
status=IncidentStatus.closed.value,
hours=24,
# We fetch stable incidents
incidents.extend(
incident_service.get_all_by_status(
db_session=db_session,
project_id=project.id,
status=IncidentStatus.stable.value,
)
)
# We fetch closed incidents in the last 24 hours
incidents.extend(
incident_service.get_all_last_x_hours_by_status(
db_session=db_session,
project_id=project.id,
status=IncidentStatus.closed.value,
hours=24,
)
)
)

blocks = []
blocks.append({"type": "header", "text": {"type": "plain_text", "text": "List of Incidents"}})

if incidents:
for incident in incidents:
if incident.visibility == Visibility.open:
if incident.visibility == Visibility.open.value:
ticket_weblink = resolve_attr(incident, "ticket.weblink")
try:
blocks.append(
Expand All @@ -523,7 +533,8 @@ def list_incidents(
f"*Type*: {incident.incident_type.name}\n"
f"*Priority*: {incident.incident_priority.name}\n"
f"*Status*: {incident.status}\n"
f"*Incident Commander*: <{incident.commander.individual.weblink}|{incident.commander.individual.name}>"
f"*Incident Commander*: <{incident.commander.individual.weblink}|{incident.commander.individual.name}>\n"
f"*Project*: {incident.project.name}"
),
},
}
Expand Down