Skip to content

Commit

Permalink
Merge pull request #43 from REBELinBLUE/cc_tray
Browse files Browse the repository at this point in the history
CC tray
  • Loading branch information
REBELinBLUE committed May 29, 2015
2 parents f2b8e5c + e543d45 commit eb149f0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace App\Http\Controllers;

use Lang;
use Response;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Repositories\Contracts\DeploymentRepositoryInterface;
Expand Down Expand Up @@ -53,4 +54,23 @@ public function index(
'projects' => $projects_by_group
]);
}

/**
* Generates an XML file for CCTray
*
* @param ProjectRepositoryInterface $projectRepository
* @return Response
*/
public function cctray(ProjectRepositoryInterface $projectRepository)
{
$projects = $projectRepository->getAll();

foreach ($projects as $project) {
$project->latest_deployment = $project->deployments->first();
}

return Response::view('cctray', [
'projects' => $projects
])->header('Content-Type', 'application/xml');
}
}
3 changes: 3 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Route::group(['middleware' => 'auth'], function () {

Route::get('/', 'DashboardController@index');

Route::get('webhook/{projects}/refresh', 'WebhookController@refresh');

Route::get('projects/{projects}', 'DeploymentController@project');
Expand Down Expand Up @@ -85,6 +86,8 @@
'uses' => 'WebhookController@webhook'
]);

Route::get('cctray.xml', 'DashboardController@cctray');

Route::get('heartbeat/{hash}', [
'as' => 'heartbeat',
'uses' => 'HeartbeatController@ping'
Expand Down
17 changes: 17 additions & 0 deletions app/Presenters/DeploymentPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
*/
class DeploymentPresenter extends Presenter
{
/**
* Returns the build status needed by CCTray
* These strings can not be translated
*
* @return string
*/
public function presentCcTrayStatus()
{
if ($this->status === Deployment::COMPLETED) {
return 'Success';
} elseif ($this->status === Deployment::FAILED) {
return 'Failure';
}

return 'Unknown';
}

/**
* Gets the translated deployment status string
*
Expand Down
19 changes: 19 additions & 0 deletions app/Presenters/ProjectPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@
*/
class ProjectPresenter extends Presenter
{
/**
* Returns the build status needed by CCTray
* These strings can not be translated
*
* @return string
*/
public function presentCcTrayStatus()
{
if ($this->status === Project::FINISHED || $this->status === Project::FAILED) {
return 'Sleeping';
} elseif ($this->status === Project::DEPLOYING) {
return 'Building';
} elseif ($this->status === Project::PENDING) {
return 'Pending';
}

return 'Unknown';
}

/**
* Gets the translated project status string
*
Expand Down
2 changes: 1 addition & 1 deletion app/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function notifications()
*/
public function deployments()
{
return $this->hasMany('App\Deployment');
return $this->hasMany('App\Deployment')->orderBy('started_at', 'DESC');
}

/**
Expand Down
13 changes: 13 additions & 0 deletions resources/views/cctray.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Projects>

@foreach ($projects as $project)

@if (!is_null($project->latest_deployment))
<Project name="{{ Lang::get('app.name') }}: {{ $project->group->name }} / {{ $project->name }}" activity="{{ $project->cc_tray_status }}" lastBuildLabel="{{ $project->latest_deployment->id }}" lastBuildStatus="{{ $project->latest_deployment->cc_tray_status }}" lastBuildTime="{{ $project->last_run->toW3cString() }}" webUrl="{{ url('deployment', $project->latest_deployment->id) }}" />
@else
<Project name="{{ Lang::get('app.name') }}: {{ $project->group->name }} / {{ $project->name }}" activity="{{ $project->cc_tray_status }}" lastBuildTime="" webUrl="{{ url('projects', $project->id) }}" />
@endif

@endforeach

</Projects>

0 comments on commit eb149f0

Please sign in to comment.