Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrik nielsen committed Dec 14, 2015
1 parent 5bb44d3 commit 7ba8fb0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Handlers/Events/Incident/IncidentReported.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function handle(IncidentWasReportedEvent $event)

$attachment = [
'fallback' => trans('slack::messages.incident.created.fallback', $replacements),
'color' => 'danger',
'color' => Utils::statusToColor($event->incident->status),
'title' => trans('slack::messages.incident.created.title', $replacements),
'title_link' => url('status-page'),
'text' => $event->incident->message,
Expand Down
13 changes: 4 additions & 9 deletions src/Handlers/Events/Incident/IncidentUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,9 @@ public function handle(IncidentWasUpdatedEvent $event)
$statuses = trans('cachet.incidents.status');
$closed = max(array_keys($statuses));

$color = 'danger';
$state = 'updated';
if ($newStatus == $closed) {
$color = 'good';
$state = 'closed';
} elseif (in_array($newStatus, [2, 3])) {
$color = 'warning';
}
$state = $newStatus == $closed
? 'closed'
: 'updated';

$replacements = [
'id' => $event->incident->id,
Expand All @@ -65,7 +60,7 @@ public function handle(IncidentWasUpdatedEvent $event)

$attachment = [
'fallback' => trans('slack::messages.incident.updated.fallback', $replacements),
'color' => $color,
'color' => Utils::statusToColor($newStatus),
'title' => trans('slack::messages.incident.updated.title', $replacements),
'title_link' => url('status-page'),
'text' => $message,
Expand Down
26 changes: 26 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static function getChanges($model)
}

/**
* Find the status on a component.
*
* @param string $componentId
*
* @return string
Expand All @@ -73,4 +75,28 @@ public static function getComponentStatus($componentId = '')

return 'n/a';
}

/**
* Map status ids to a slack color.
*
* @param int $status
*
* @return string
*/
public static function statusToColor($status)
{
$colormap = [
0 => 'good', // 'Scheduled'
1 => 'danger', // 'Investigating'
2 => 'warning', // 'Identified'
3 => 'warning', // 'Watching'
4 => 'good', // 'Fixed'
];

if (isset($colormap[$status])) {
return $colormap[$status];
}

return '';
}
}

0 comments on commit 7ba8fb0

Please sign in to comment.