diff --git a/app/Commands/DeployProject.php b/app/Commands/DeployProject.php index 421c58535..134244360 100644 --- a/app/Commands/DeployProject.php +++ b/app/Commands/DeployProject.php @@ -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; @@ -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 + 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(); diff --git a/app/Commands/QueueDeployment.php b/app/Commands/QueueDeployment.php index 7068d6095..1ff073cbe 100644 --- a/app/Commands/QueueDeployment.php +++ b/app/Commands/QueueDeployment.php @@ -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); } } } @@ -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; diff --git a/app/Http/Controllers/CommandController.php b/app/Http/Controllers/CommandController.php index 3f9ed9221..47d471e56 100644 --- a/app/Http/Controllers/CommandController.php +++ b/app/Http/Controllers/CommandController.php @@ -1,7 +1,6 @@ Command::DO_CLONE, @@ -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') @@ -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(); @@ -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(); @@ -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; @@ -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 [ @@ -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())); @@ -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); } } diff --git a/app/Http/Controllers/DeploymentController.php b/app/Http/Controllers/DeploymentController.php index c3dd7823a..245c42830 100644 --- a/app/Http/Controllers/DeploymentController.php +++ b/app/Http/Controllers/DeploymentController.php @@ -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) { diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php index f27c687a3..f6b26a630 100644 --- a/app/Http/Controllers/NotificationController.php +++ b/app/Http/Controllers/NotificationController.php @@ -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. * @@ -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())); @@ -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())); diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 4c0af55f0..fc113f5aa 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -1,7 +1,6 @@ null, Command::DO_INSTALL => null, @@ -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(); @@ -170,12 +166,11 @@ 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 [ @@ -183,29 +178,15 @@ public function destroy($project_id) ]; } - /** - * 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)); diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index e17e8015c..11256566d 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -16,12 +16,12 @@ class ServerController extends Controller /** * Shows the specified server * - * @param int $server_id + * @param Server $server * @return Response */ - public function show($server_id) + public function show(Server $server) { - return Server::findOrFail($server_id); + return $server; } /** @@ -48,15 +48,13 @@ public function store(StoreServerRequest $request) /** * Update the specified server in storage. * - * @param int $server_id + * @param Server $server * @param StoreServerRequest $request * @return Response * @todo Use mass assignment if possible */ - public function update($server_id, StoreServerRequest $request) + public function update(Server $server, StoreServerRequest $request) { - $server = Server::findOrFail($server_id); - if ($server->ip_address != $request->ip_address) { $server->status = Server::UNTESTED; } @@ -74,12 +72,11 @@ public function update($server_id, StoreServerRequest $request) /** * Remove the specified server from storage. * - * @param int $server_id + * @param Server $server * @return Response */ - public function destroy($server_id) + public function destroy(Server $server) { - $server = Server::findOrFail($server_id); $server->delete(); return [ @@ -90,13 +87,11 @@ public function destroy($server_id) /** * Queues a connection test for the specified server * - * @param int $server_id + * @param Server $server * @return Response */ - public function test($server_id) + public function test(Server $server) { - $server = Server::findOrFail($server_id); - $server->status = Server::TESTING; $server->save(); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index d2174681f..7bcd6ca28 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -54,15 +54,13 @@ public function store(StoreUserRequest $request) /** * Update the specified user in storage. * - * @param int $user_id + * @param User $user * @param StoreUserRequest $request * @return Response * @todo Use mass assignment if possible */ - public function update($user_id, StoreUserRequest $request) + public function update(User $user, StoreUserRequest $request) { - $user = User::findOrFail($user_id); - $user->name = $request->name; $user->email = $request->email; @@ -80,12 +78,11 @@ public function update($user_id, StoreUserRequest $request) /** * Remove the specified user from storage. * - * @param int $user_id + * @param User $user * @return Response */ - public function destroy($user_id) + public function destroy(User $user) { - $user = User::findOrFail($user_id); $user->delete(); return [ diff --git a/app/Http/Requests/StoreUserRequest.php b/app/Http/Requests/StoreUserRequest.php index 786df7019..e0e239300 100644 --- a/app/Http/Requests/StoreUserRequest.php +++ b/app/Http/Requests/StoreUserRequest.php @@ -27,8 +27,7 @@ public function rules() if (Input::get('password') !== '') { $rules['password'] = 'min:6'; - } - else { + } else { unset($rules['password']); } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 6781d0132..481cb447e 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -13,38 +13,21 @@ Route::group(['middleware' => 'auth'], function () { - Route::get('/', [ - 'uses' => 'DashboardController@index' - ]); - - Route::get('webhook/{id}/refresh', [ - 'uses' => 'WebhookController@refresh' - ]); - - Route::get('projects/{id}', [ - 'uses' => 'ProjectController@show' - ]); - - Route::resource('admin/projects', 'ProjectController', [ - 'only' => ['index', 'store', 'update', 'destroy'] - ]); + Route::get('/', 'DashboardController@index'); + Route::get('webhook/{projects}/refresh', 'WebhookController@refresh'); + Route::get('projects/{projects}', 'ProjectController@show'); - Route::post('projects/{id}/deploy', [ + Route::post('projects/{projects}/deploy', [ 'as' => 'deploy', 'uses' => 'ProjectController@deploy' ]); // Deployment details - Route::get('deployment/{id}', [ // FIXME Should this be on the deployment controller? + Route::get('deployment/{deployments}', [ // FIXME Should this be on the deployment controller? 'as' => 'deployment', 'uses' => 'DeploymentController@show' ]); - // Servers - Route::get('projects/{id}/servers', [ - 'uses' => 'ProjectController@servers' - ]); - Route::resource('servers', 'ServerController', [ 'only' => ['show', 'store', 'update', 'destroy'] ]); @@ -53,39 +36,38 @@ 'only' => ['store', 'update', 'destroy'] ]); - Route::get('servers/{id}/test', [ - 'uses' => 'ServerController@test' - ]); + Route::get('servers/{servers}/test', 'ServerController@test'); - // Commands - Route::get('status/{id}', [ - 'uses' => 'CommandController@status' - ]); - - Route::get('log/{id}', [ - 'uses' => 'CommandController@log' - ]); + Route::get('status/{log}', 'CommandController@status'); + Route::get('log/{log}', 'CommandController@log'); Route::resource('commands', 'CommandController', [ 'only' => ['store', 'update', 'destroy'] ]); - Route::post('commands/reorder', [ - 'uses' => 'CommandController@reorder' - ]); + Route::post('commands/reorder', 'CommandController@reorder'); - Route::get('projects/{id}/commands/{command}', [ + Route::get('projects/{projects}/commands/{step}', [ 'as' => 'commands', 'uses' => 'CommandController@listing' ]); - Route::resource('admin/users', 'UserController', [ - 'only' => ['index', 'store', 'update', 'destroy'] - ]); + Route::group(['prefix' => 'admin'], function() { + + Route::resource('projects', 'ProjectController', [ + 'only' => ['index', 'store', 'update', 'destroy'] + ]); + + Route::resource('users', 'UserController', [ + 'only' => ['index', 'store', 'update', 'destroy'] + ]); + + Route::resource('groups', 'GroupController', [ + 'only' => ['index', 'store', 'update'] + ]); + + }); - Route::resource('admin/groups', 'GroupController', [ - 'only' => ['index', 'store', 'update'] - ]); }); // Webhooks diff --git a/app/Project.php b/app/Project.php index bdfc08413..68ae7310b 100644 --- a/app/Project.php +++ b/app/Project.php @@ -26,6 +26,13 @@ class Project extends Model protected $hidden = ['private_key', 'public_key', 'created_at', 'deleted_at', 'updated_at', 'last_run', 'servers', 'commands', 'hash', 'status']; + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = ['name', 'repository', 'branch', 'group_id', 'builds_to_keep', 'url', 'build_url']; + /** * Overwrite Laravel's getDate() function to add additional dates * diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 39b2ac273..50b28b40d 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -28,7 +28,16 @@ public function boot(Router $router) parent::boot($router); $router->pattern('id', '[0-9]+'); - $router->pattern('command', '(clone|install|activate|purge)'); + $router->pattern('step', '(clone|install|activate|purge)'); + + $router->model('commands', 'App\Command'); + $router->model('deployments', 'App\Deployment'); + $router->model('groups', 'App\Group'); + $router->model('notifications', 'App\Notification'); + $router->model('projects', 'App\Project'); + $router->model('servers', 'App\Server'); + $router->model('log', 'App\ServerLog'); + $router->model('users', 'App\User'); } /** diff --git a/resources/views/dialogs/command.blade.php b/resources/views/dialogs/command.blade.php index 61b688ec3..fe91cd03a 100644 --- a/resources/views/dialogs/command.blade.php +++ b/resources/views/dialogs/command.blade.php @@ -26,7 +26,7 @@
@{{ release }}
- {{ Lang::get('commands.release_id') }}, e.g. {{ date('YmdHis') }}@{{ release_path }}
- {{ Lang::get('commands.release_path') }}, e.g. /var/www/releases/{{ date('YmdHis') }}/