Skip to content

Commit

Permalink
fix: render update summary properly
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjeevan committed Apr 8, 2024
1 parent 972bbcd commit 3f38d07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
4 changes: 1 addition & 3 deletions backend/app/services/slack/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ def create_incident_update(
) -> SlackMessage:
renderer = IncidentUpdateRenderer(
creator=creator,
incident=incident,
new_severity=incident_update.new_incident_severity,
new_status=incident_update.new_incident_status,
summary=incident_update.summary,
incident_update=incident_update,
)
blocks = renderer.render()

Expand Down
19 changes: 8 additions & 11 deletions backend/app/services/slack/renderer/incident_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import structlog

from app.models import Incident, IncidentSeverity, IncidentStatus, User
from app.models import IncidentUpdate, User

logger = structlog.get_logger(logger_name=__name__)

Expand All @@ -11,16 +11,13 @@ class IncidentUpdateRenderer:
def __init__(
self,
creator: User,
incident: Incident,
new_status: IncidentStatus | None = None,
new_severity: IncidentSeverity | None = None,
incident_update: IncidentUpdate,
summary: str | None = None,
):
self.creator = creator
self.incident = incident
self.new_status = new_status
self.new_severity = new_severity
self.incident = incident_update
self.summary = summary
self.incident_update = incident_update

def render(self) -> list[dict[str, Any]]:
blocks: list[dict[str, Any]] = [
Expand All @@ -30,23 +27,23 @@ def render(self) -> list[dict[str, Any]]:
}
]

if self.new_status and self.new_status.id != self.incident.incident_status.id:
if self.incident_update.new_incident_status:
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Status: {self.incident.incident_status.name} -> {self.new_status.name}",
"text": f"Status: {self.incident_update.previous_incident_status.name} -> {self.incident_update.new_incident_status.name}",
},
}
)
if self.new_severity and self.new_severity.id != self.incident.incident_severity.id:
if self.incident_update.new_incident_severity:
blocks.append(
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"Severity: {self.incident.incident_severity.name} -> {self.new_severity.name}",
"text": f"Severity: {self.incident_update.previous_incident_severity.name} -> {self.incident_update.new_incident_severity.name}",
},
}
)
Expand Down

0 comments on commit 3f38d07

Please sign in to comment.