Skip to content

Commit

Permalink
Merge pull request #1 from REBELinBLUE/route_models
Browse files Browse the repository at this point in the history
Route models
  • Loading branch information
REBELinBLUE committed Apr 8, 2015
2 parents 7a288ef + 64c1126 commit a20485f
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 150 deletions.
3 changes: 1 addition & 2 deletions app/Commands/DeployProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function handle()
$this->deployment->status = Deployment::COMPLETED;
$project->status = Project::FINISHED;
} catch (\Exception $error) {
echo $error;
$this->deployment->status = Deployment::FAILED;
$project->status = Project::FAILED;

Expand Down Expand Up @@ -145,7 +144,7 @@ private function updateRepoInfo()
unlink($wrapper);

if (!$process->isSuccessful()) {
throw new \RuntimeException('Could not get repository info'); // FIXME: Handle this situation as it is then unclear what went wrong

This comment has been minimized.

Copy link
@REBELinBLUE

REBELinBLUE Apr 8, 2015

Author Owner

PHPCS: Line exceeds 120 characters; contains 175 characters

throw new \RuntimeException('Could not get repository info - ' . $process->getErrorOutput()); // FIXME: Handle this situation as it is then unclear what went wrong
}

$git_info = $process->getOutput();
Expand Down
11 changes: 6 additions & 5 deletions app/Commands/QueueDeployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public function handle()

if (isset($hooks[$stage]['before'])) {
foreach ($hooks[$stage]['before'] as $hook) {
$this->create_step($before, $hook);
$this->createStep($before, $hook);
}
}

$this->create_step($stage);
$this->createStep($stage);

if (isset($hooks[$stage]['after'])) {
foreach ($hooks[$stage]['after'] as $hook) {
$this->create_step($after, $hook);
$this->createStep($after, $hook);
}
}
}
Expand All @@ -104,13 +104,14 @@ public function handle()

/**
* Create an instance of DeployStep and a ServerLog entry for each server
*
*
* @param int $stage
* @param Command|null $command
* @return void
* @todo Only create instances of ServerLog for each server which is assigned the command
*/
private function create_step($stage, Stage $command = null) {
private function createStep($stage, Stage $command = null)
{
$step = new DeployStep;
$step->stage = $stage;

Expand Down
34 changes: 14 additions & 20 deletions app/Http/Controllers/CommandController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace App\Http\Controllers;

use Input;
use Response;
use App\Project;
use App\Command;
use App\ServerLog;
Expand All @@ -18,11 +17,12 @@ class CommandController extends Controller
/**
* Display a listing of before/after commands for the supplied stage
*
* @param Project $project
* @param int $project_id
* @param string $action Either clone, install, activate or purge
* @return Response
*/
public function listing($project_id, $action)
public function listing(Project $project, $action)
{
$types = [
'clone' => Command::DO_CLONE,
Expand All @@ -31,8 +31,6 @@ public function listing($project_id, $action)
'purge' => Command::DO_PURGE
];

$project = Project::findOrFail($project_id);

$commands = Command::where('project_id', $project->id)
->whereIn('step', array($types[$action] - 1, $types[$action] + 1))
->orderBy('order')
Expand Down Expand Up @@ -64,8 +62,8 @@ public function listing($project_id, $action)
*/
public function store(StoreCommandRequest $request)
{
$max = Command::where('project_id', Input::get('project_id'))
->where('step', Input::get('step'))
$max = Command::where('project_id', $request->project_id)
->where('step', $request->step)
->orderBy('order', 'desc')
->first();

Expand All @@ -79,7 +77,7 @@ public function store(StoreCommandRequest $request)
$command->user = $request->user;
$command->project_id = $request->project_id;
$command->script = $request->script;
$command->step = ucwords($request->step);
$command->step = $request->step;
$command->order = $order;
$command->save();

Expand All @@ -93,15 +91,14 @@ public function store(StoreCommandRequest $request)
/**
* Update the specified command in storage.
*
* @param int $command_id
* @param Command $command
* @param StoreCommandRequest $request
* @return Response
* @todo Use mass assignment
* @todo Change attach/detach to sync
*/
public function update($command_id, StoreCommandRequest $request)
public function update(Command $command, StoreCommandRequest $request)
{
$command = Command::findOrFail($command_id);
$command->name = $request->name;
$command->user = $request->user;
$command->script = $request->script;
Expand All @@ -118,12 +115,11 @@ public function update($command_id, StoreCommandRequest $request)
/**
* Remove the specified command from storage.
*
* @param int $command_id
* @param Command $command
* @return Response
*/
public function destroy($command_id)
public function destroy(Command $command)
{
$command = Command::findOrFail($command_id);
$command->delete();

return [
Expand Down Expand Up @@ -158,15 +154,13 @@ public function reorder()
/**
* Gets the status of a particular deployment step
*
* @param int $log_id
* @param ServerLog $log
* @param boolean $include_log
* @return Response
* @todo Move this to deployment controller
*/
public function status($log_id, $include_log = false)
public function status(ServerLog $log, $include_log = false)
{
$log = ServerLog::findOrFail($log_id);

$log->started = ($log->started_at ? $log->started_at->format('g:i:s A') : null);
$log->finished = ($log->finished_at ? $log->finished_at->format('g:i:s A') : null);
$log->runtime = ($log->runtime() === false ? null : human_readable_duration($log->runtime()));
Expand All @@ -182,12 +176,12 @@ public function status($log_id, $include_log = false)
/**
* Gets the log output of a particular deployment step
*
* @param int $log_id
* @param ServerLog $log
* @return Response
* @todo Move this to deployment controller
*/
public function log($log_id)
public function log(ServerLog $log)
{
return $this->status($log_id, true);
return $this->status($log, true);
}
}
6 changes: 2 additions & 4 deletions app/Http/Controllers/DeploymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ class DeploymentController extends Controller
/**
* Show the deployment details
*
* @param int $deployment_id
* @param Deployment $deployment
* @return Response
*/
public function show($deployment_id)
public function show(Deployment $deployment)
{
$deployment = Deployment::findOrFail($deployment_id);

$output = [];
foreach ($deployment->steps as $step) {
foreach ($step->servers as $server) {
Expand Down
27 changes: 12 additions & 15 deletions app/Http/Controllers/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@
*/
class NotificationController extends Controller
{
/**
* Show the specified notification
*
* @param int $notification_id
* @return Response
* @deprecated
* @todo Remove this as I do not think it is used
*/
public function show($notification_id)
{
return Notification::findOrFail($notification_id);
}

/**
* Store a newly created notification in storage.
*
Expand All @@ -32,7 +19,12 @@ public function show($notification_id)
*/
public function store(StoreNotificationRequest $request)
{
$notification = Notification::create($request->only('name', 'channel', 'webhook', 'project_id'));
$notification = Notification::create($request->only(
'name',
'channel',
'webhook',
'project_id'
));

Queue::pushOn('notify', new Notify($notification, $notification->testPayload()));

Expand All @@ -48,7 +40,12 @@ public function store(StoreNotificationRequest $request)
*/
public function update(Notification $notification, StoreNotificationRequest $request)
{
$notification->update($request->only('name', 'channel', 'webhook', 'project_id'));
$notification->update($request->only(
'name',
'channel',
'webhook',
'project_id'
));

Queue::pushOn('notify', new Notify($notification, $notification->testPayload()));

Expand Down
53 changes: 17 additions & 36 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace App\Http\Controllers;

use Lang;
use Response;
use Carbon\Carbon;
use App\Command;
use App\Project;
Expand Down Expand Up @@ -43,13 +42,11 @@ public function index()
/**
* The details of an individual project
*
* @param int $project_id The ID of the project to display
* @param Project $project
* @return View
*/
public function show($project_id)
public function show(Project $project)
{
$project = Project::findOrFail($project_id);

$commands = [
Command::DO_CLONE => null,
Command::DO_INSTALL => null,
Expand Down Expand Up @@ -138,22 +135,21 @@ public function store(StoreProjectRequest $request)
/**
* Update the specified project in storage.
*
* @param int $project_id
* @param Project $project
* @param StoreProjectRequest $request
* @return Response
* @todo Use mass assignment
*/
public function update($project_id, StoreProjectRequest $request)
public function update(Project $project, StoreProjectRequest $request)
{
$project = Project::findOrFail($project_id);

$project->name = $request->name;
$project->repository = $request->repository;
$project->branch = $request->branch;
$project->group_id = $request->group_id;
$project->builds_to_keep = $request->builds_to_keep;
$project->url = $request->url;
$project->build_url = $request->build_url;
$project->update($request->only(
'name',
'repository',
'branch',
'group_id',
'builds_to_keep',
'url',
'build_url'
));

$project->save();

Expand All @@ -170,42 +166,27 @@ public function update($project_id, StoreProjectRequest $request)
/**
* Remove the specified project from storage.
*
* @param int $project_id
* @param Project $project
* @return Response
*/
public function destroy($project_id)
public function destroy(Project $project)
{
$project = Project::findOrFail($project_id);
$project->delete();

return [
'success' => true
];
}

/**
* Gets the servers for the specified project
*
* @param int $project_id
* @returnResponse
*/
public function servers($project_id)
{
$project = Project::findOrFail($project_id);

return $project->servers;
}

/**
* Adds a deployment for the specified project to the queue
*
* @param int $project_id
* @param Project $project
* @return Response
* @todo Don't allow this to run if there is already a pending deploy or no servers
*/
public function deploy($project_id)
public function deploy(Project $project)
{
$project = Project::findOrFail($project_id);
$deployment = new Deployment;

$this->dispatch(new QueueDeployment($project, $deployment));
Expand Down
Loading

0 comments on commit a20485f

Please sign in to comment.