Web notifications small fixes. Issue #156.

This commit is contained in:
Dmitry Khomutov 2018-04-09 20:07:04 +07:00
commit 56fc76d4e5
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
7 changed files with 36 additions and 69 deletions

View file

@ -2,13 +2,7 @@
namespace PHPCensor\Service;
use PHPCensor\Config;
use Pheanstalk\Pheanstalk;
use Pheanstalk\PheanstalkInterface;
use PHPCensor\BuildFactory;
use PHPCensor\Model\Build;
use PHPCensor\Model\Project;
use PHPCensor\Store\BuildStore;
/**
* A service that listens for creation, duplication and deletion of builds for web notification UI.
@ -18,8 +12,11 @@ class WebNotificationService
/**
* Similar to BuildController::formatBuilds() but uses
* pure object to be used for rendering web notifications.
*
* @param array $builds
*
* @return array Formatted builds
*
* @see \PHPCensor\Controller\WidgetLastBuildsController::webNotificationUpdate().
*/
public static function formatBuilds($builds)
@ -37,7 +34,9 @@ class WebNotificationService
/**
* Provides structured keys for web notification.
*
* @param Build $build
*
* @return array
*/
public static function formatBuild($build)
@ -45,15 +44,11 @@ class WebNotificationService
if (empty($build) || is_null($build)) {
return [];
}
$status = $build->getStatus();
$datePerformed = '';
$dateFinished = '';
/*
BUG: Lang::out() automatically renders the values for
either 'created_x' or 'started_x' instead of just
returning them.
*/
$status = $build->getStatus();
$datePerformed = '';
$dateFinished = '';
if ($status === Build::STATUS_PENDING) {
$datePerformed = 'Created: ' . $build->getCreateDate()->format('H:i');
} elseif ($status === Build::STATUS_RUNNING) {
@ -66,13 +61,9 @@ class WebNotificationService
return [
'branch' => $build->getBranch(),
'url' => APP_URL .
'build/view/' .
$build->getId(),
'url' => APP_URL . 'build/view/' . $build->getId(),
'committer_email' => $build->getCommitterEmail(),
'img_src' => 'https://www.gravatar.com/avatar/' .
md5($build->getCommitterEmail()) .
'?d=mm&s=40',
'img_src' => 'https://www.gravatar.com/avatar/' . md5($build->getCommitterEmail()) . '?d=mm&s=40',
'project_title' => $build->getProject()->getTitle(),
'status' => $status,
'date_performed' => $datePerformed,