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

CC tray #43

Merged
merged 6 commits into from
May 29, 2015
Merged
Show file tree
Hide file tree
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
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>