From aa75f7b36e44fcb91550b0717321f73253ae638e Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 21:46:22 +0100 Subject: [PATCH 01/66] Adding a template attribute to projects --- app/Group.php | 1 + app/Project.php | 14 ++++++++- .../EloquentProjectRepository.php | 1 + ...15_06_16_213224_add_is_template_column.php | 31 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2015_06_16_213224_add_is_template_column.php diff --git a/app/Group.php b/app/Group.php index c54b09055..89c4a3a34 100644 --- a/app/Group.php +++ b/app/Group.php @@ -42,6 +42,7 @@ class Group extends Model public function projects() { return $this->hasMany('App\Project') + ->notTemplates() ->orderBy('name'); } diff --git a/app/Project.php b/app/Project.php index 4124af899..9f70d74f7 100644 --- a/app/Project.php +++ b/app/Project.php @@ -30,7 +30,8 @@ class Project extends ProjectRelation implements PresentableInterface protected $hidden = ['private_key', 'created_at', 'deleted_at', 'updated_at', 'hash', 'updated_at', 'servers', 'commands', 'hash', 'notifyEmails', 'group', 'servers', 'commands', 'heartbeats', 'checkUrls', - 'notifications', 'deployments', 'shareFiles', 'projectFiles']; + 'notifications', 'deployments', 'shareFiles', 'projectFiles', + 'is_template']; /** * The attributes that are mass assignable. @@ -61,6 +62,7 @@ class Project extends ProjectRelation implements PresentableInterface protected $casts = [ 'status' => 'integer', 'builds_to_keep' => 'integer', + 'is_template' => 'boolean' ]; /** @@ -262,6 +264,16 @@ public function getWebhookUrlAttribute() return route('webhook', $this->hash); } + public function scopeTemplates($query) + { + return $query->where('is_template', '=', true); + } + + public function scopeNotTemplates($query) + { + return $query->where('is_template', '=', false); + } + /** * Generates an SSH key and sets the private/public key properties. * diff --git a/app/Repositories/EloquentProjectRepository.php b/app/Repositories/EloquentProjectRepository.php index 03ec7e5a5..39ab7bb09 100644 --- a/app/Repositories/EloquentProjectRepository.php +++ b/app/Repositories/EloquentProjectRepository.php @@ -29,6 +29,7 @@ public function __construct(Project $model) public function getAll() { return $this->model + ->notTemplates() ->orderBy('name') ->get(); } diff --git a/database/migrations/2015_06_16_213224_add_is_template_column.php b/database/migrations/2015_06_16_213224_add_is_template_column.php new file mode 100644 index 000000000..46a62dfcf --- /dev/null +++ b/database/migrations/2015_06_16_213224_add_is_template_column.php @@ -0,0 +1,31 @@ +boolean('is_template')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('projects', function (Blueprint $table) { + $table->dropColumn('is_template'); + }); + } +} From 00c44049c0fbd7eb6c28fac058ff73dbda785de1 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:11:59 +0100 Subject: [PATCH 02/66] Add the ability to include newly created servers in all existing commands --- .../Controllers/Resources/ServerController.php | 11 ++++++++++- app/Http/Requests/StoreServerRequest.php | 11 ++++++----- app/Jobs/DeployProject.php | 2 +- resources/assets/js/servers.js | 17 ++++++++++------- resources/lang/en/servers.php | 5 +++-- resources/views/dialogs/server.blade.php | 12 ++++++++++-- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/Resources/ServerController.php b/app/Http/Controllers/Resources/ServerController.php index 740564df8..23a31ef12 100644 --- a/app/Http/Controllers/Resources/ServerController.php +++ b/app/Http/Controllers/Resources/ServerController.php @@ -21,7 +21,7 @@ class ServerController extends ResourceController */ public function store(StoreServerRequest $request) { - return Server::create($request->only( + $server = Server::create($request->only( 'name', 'user', 'ip_address', @@ -30,6 +30,15 @@ public function store(StoreServerRequest $request) 'project_id', 'deploy_code' )); + + // Add the server to the existing commands + if ($request->has('add_commands') && $request->add_commands === true) { + foreach ($server->project->commands as $command) { + $command->servers()->attach($server->id); + } + } + + return $server; } /** diff --git a/app/Http/Requests/StoreServerRequest.php b/app/Http/Requests/StoreServerRequest.php index fd505ee03..7527e37ab 100644 --- a/app/Http/Requests/StoreServerRequest.php +++ b/app/Http/Requests/StoreServerRequest.php @@ -43,11 +43,12 @@ function ($attribute, $value, $parameters) { public function rules() { return [ - 'name' => 'required|max:255', - 'user' => 'required|max:255', - 'ip_address' => 'required|host', - 'path' => 'required', - 'project_id' => 'required|integer|exists:projects,id' + 'name' => 'required|max:255', + 'user' => 'required|max:255', + 'ip_address' => 'required|host', + 'path' => 'required', + 'add_commands' => 'boolean', + 'project_id' => 'required|integer|exists:projects,id' ]; } } diff --git a/app/Jobs/DeployProject.php b/app/Jobs/DeployProject.php index abe25c9d4..157a8e096 100644 --- a/app/Jobs/DeployProject.php +++ b/app/Jobs/DeployProject.php @@ -19,7 +19,7 @@ use Symfony\Component\Process\Process; /** - * Deploys an actual project + * Deploys an actual project. * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * TODO: rewrite this as it is doing way too much and is very messy now. */ diff --git a/resources/assets/js/servers.js b/resources/assets/js/servers.js index 6b3b7f04d..52d4fd60e 100644 --- a/resources/assets/js/servers.js +++ b/resources/assets/js/servers.js @@ -16,6 +16,7 @@ var app = app || {}; $('.callout-danger', modal).hide(); $('.has-error', modal).removeClass('has-error'); $('.label-danger', modal).remove(); + $('#add-server-command', modal).hide(); if (button.hasClass('btn-edit')) { title = Lang.servers.edit; @@ -28,6 +29,7 @@ var app = app || {}; $('#server_user').val(''); $('#server_path').val(''); $('#server_deploy_code').prop('checked', true); + $('#add-server-command', modal).show(); } modal.find('.modal-title span').text(title); @@ -82,13 +84,14 @@ var app = app || {}; } server.save({ - name: $('#server_name').val(), - ip_address: $('#server_address').val(), - port: $('#server_port').val(), - user: $('#server_user').val(), - path: $('#server_path').val(), - deploy_code: $('#server_deploy_code').is(':checked'), - project_id: $('input[name="project_id"]').val() + name: $('#server_name').val(), + ip_address: $('#server_address').val(), + port: $('#server_port').val(), + user: $('#server_user').val(), + path: $('#server_path').val(), + deploy_code: $('#server_deploy_code').is(':checked'), + project_id: $('input[name="project_id"]').val(), + add_commands: $('#server_commands').is(':checked') }, { wait: true, success: function(model, response, options) { diff --git a/resources/lang/en/servers.php b/resources/lang/en/servers.php index 0837778e0..d2ca69f46 100644 --- a/resources/lang/en/servers.php +++ b/resources/lang/en/servers.php @@ -19,7 +19,8 @@ 'testing' => 'Testing', 'failed' => 'Failed', 'untested' => 'Untested', - 'deploy_code' => 'Deploy code', - 'deploy_description' => 'Whether or not the code should be deployed to this server' + 'options' => 'Options', + 'deploy_code' => 'Code should be deployed to this server', + 'add_command' => 'Add the new server to all existing commands' ]; diff --git a/resources/views/dialogs/server.blade.php b/resources/views/dialogs/server.blade.php index 14a1b66dd..84a9b288c 100644 --- a/resources/views/dialogs/server.blade.php +++ b/resources/views/dialogs/server.blade.php @@ -35,13 +35,21 @@
- +
+ @if ($project->commands->count() > 0) +
+ +
+ @endif
+ @if (count($templates) > 0) +
+ + +
+ @endif
From 08729c3fdbd6e621771479b65d2e14c3969b013c Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:12:48 +0100 Subject: [PATCH 04/66] Creating project actually from a template --- app/Jobs/SetupProject.php | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/Jobs/SetupProject.php diff --git a/app/Jobs/SetupProject.php b/app/Jobs/SetupProject.php new file mode 100644 index 000000000..1e34baa34 --- /dev/null +++ b/app/Jobs/SetupProject.php @@ -0,0 +1,47 @@ +project = $project; + $this->template = $template; + } + + /** + * Execute the command. + * + * @return void + */ + public function handle() + { + // FIXME: Also copy persistent files + foreach ($this->template->commands as $command) { + + $data = $command->toArray(); + $data['project_id'] = $this->project->id; + + Command::create($data); + } + } +} From ec746ee2e5576ac6ef6a21f19a39e4d06b82260c Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:13:02 +0100 Subject: [PATCH 05/66] Adding templates to sidebar --- resources/views/_partials/sidebar.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/views/_partials/sidebar.blade.php b/resources/views/_partials/sidebar.blade.php index e7e50ad3e..810b44055 100644 --- a/resources/views/_partials/sidebar.blade.php +++ b/resources/views/_partials/sidebar.blade.php @@ -31,6 +31,7 @@ From 417e42e9193592c9ab40c677551a4fe6e18f1c93 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:28:24 +0100 Subject: [PATCH 06/66] Seeding some example templates --- database/seeds/DatabaseSeeder.php | 1 + database/seeds/TemplateSeeder.php | 48 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 database/seeds/TemplateSeeder.php diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index efd927bb4..dcec25d74 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -21,5 +21,6 @@ public function run() $this->call('CommandTableSeeder'); $this->call('NotificationTableSeeder'); $this->call('HeartbeatTableSeeder'); + $this->call('TemplateSeeder'); } } diff --git a/database/seeds/TemplateSeeder.php b/database/seeds/TemplateSeeder.php new file mode 100644 index 000000000..fb05d79c0 --- /dev/null +++ b/database/seeds/TemplateSeeder.php @@ -0,0 +1,48 @@ + 'Laravel', + 'is_template' => true, + 'group_id' => 1 // FIXME: Horrible hack + ]); + + Project::create([ + 'name' => 'Wordpress', + 'is_template' => true, + 'group_id' => 1 + ]); + + Command::create([ + 'name' => 'Down', + 'script' => "php artisan down", + 'project_id' => $laravel->id, + 'user' => 'vagrant', + 'step' => Command::BEFORE_ACTIVATE + ]); + + Command::create([ + 'name' => 'Run Migrations', + 'script' => "php artisan migrate --force", + 'project_id' => $laravel->id, + 'user' => 'vagrant', + 'step' => Command::BEFORE_ACTIVATE + ]); + + Command::create([ + 'name' => 'Up', + 'script' => "php artisan up", + 'project_id' => $laravel->id, + 'user' => 'vagrant', + 'step' => Command::BEFORE_ACTIVATE + ]); + } +} \ No newline at end of file From 8a0a5d0e920dfb5a53a90c5c13464add9a812c29 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:28:53 +0100 Subject: [PATCH 07/66] Fixing use statements --- app/Jobs/SetupProject.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Jobs/SetupProject.php b/app/Jobs/SetupProject.php index 1e34baa34..f51a67db3 100644 --- a/app/Jobs/SetupProject.php +++ b/app/Jobs/SetupProject.php @@ -2,15 +2,15 @@ namespace App\Jobs; -use App\Commands\Command; use App\Command; +use App\Jobs\Job; use App\Project; use Illuminate\Contracts\Bus\SelfHandling; /** * A class to handle cloning the command templates for the project. */ -class SetupProject extends Command implements SelfHandling +class SetupProject extends Job implements SelfHandling { private $project; private $template; From 458855efab2df3930a711763bd94dbc703acf7fd Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:29:03 +0100 Subject: [PATCH 08/66] Fixing validation rule --- app/Http/Requests/StoreProjectRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/StoreProjectRequest.php b/app/Http/Requests/StoreProjectRequest.php index 755830f49..3e2b7c562 100644 --- a/app/Http/Requests/StoreProjectRequest.php +++ b/app/Http/Requests/StoreProjectRequest.php @@ -56,7 +56,7 @@ public function rules() 'branch' => 'required|max:255', 'group_id' => 'required|integer|exists:groups,id', 'builds_to_keep' => 'required|integer|min:1|max:20', - 'template_id' => 'integer|exists:templates,id', + 'template_id' => 'integer|exists:projects,id,is_template,1', 'url' => 'url', 'build_url' => 'url' ]; From 040ed343a470aaf84ebd6f18261e547197ca99d2 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:32:45 +0100 Subject: [PATCH 09/66] Missing docblock --- app/Project.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Project.php b/app/Project.php index 9f70d74f7..ed3afd029 100644 --- a/app/Project.php +++ b/app/Project.php @@ -38,7 +38,7 @@ class Project extends ProjectRelation implements PresentableInterface * * @var array */ - protected $fillable = ['name', 'repository', 'branch', 'group_id', 'builds_to_keep', 'url', 'build_url']; + protected $fillable = ['name', 'repository', 'branch', 'group_id', 'builds_to_keep', 'url', 'build_url', 'is_template']; /** * The fields which should be treated as Carbon instances. @@ -264,11 +264,23 @@ public function getWebhookUrlAttribute() return route('webhook', $this->hash); } + /** + * Query scope to only show templates + * + * @param object $query + * @return object + */ public function scopeTemplates($query) { return $query->where('is_template', '=', true); } + /** + * Query scope to not show templates + * + * @param object $query + * @return object + */ public function scopeNotTemplates($query) { return $query->where('is_template', '=', false); From eb8b8d89b2d238a26895157f2099f7cd108db83f Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:33:04 +0100 Subject: [PATCH 10/66] Pass in the template ID rather than the project to SetupProject --- app/Http/Controllers/Admin/ProjectController.php | 3 +-- app/Jobs/SetupProject.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Admin/ProjectController.php b/app/Http/Controllers/Admin/ProjectController.php index cfa1f6522..840aac326 100644 --- a/app/Http/Controllers/Admin/ProjectController.php +++ b/app/Http/Controllers/Admin/ProjectController.php @@ -53,11 +53,10 @@ public function store(StoreProjectRequest $request) 'build_url' )); - // FIXME: Should this be an event rather than a command? if ($request->has('template_id')) { $this->dispatch(new SetupProject( $project, - Template::find($request->template_id) + $request->template_id )); } diff --git a/app/Jobs/SetupProject.php b/app/Jobs/SetupProject.php index f51a67db3..1b9ee12ca 100644 --- a/app/Jobs/SetupProject.php +++ b/app/Jobs/SetupProject.php @@ -13,19 +13,19 @@ class SetupProject extends Job implements SelfHandling { private $project; - private $template; + private $template_id; /** * Create a new command instance. * * @param Project $project - * @param Project $template + * @param int $template_id * @return SetupProject */ - public function __construct(Project $project, Project $template) + public function __construct(Project $project, $template_id) { - $this->project = $project; - $this->template = $template; + $this->project = $project; + $this->template_id = $template_id; } /** @@ -35,8 +35,9 @@ public function __construct(Project $project, Project $template) */ public function handle() { - // FIXME: Also copy persistent files - foreach ($this->template->commands as $command) { + $template = Project::findOrFail($this->template_id); + + foreach ($template->commands as $command) { $data = $command->toArray(); $data['project_id'] = $this->project->id; From 22cbda15a12efa5e2559d687e0ff53659a0d1495 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 22:39:15 +0100 Subject: [PATCH 11/66] Starting to add admin screens --- .../Controllers/Admin/TemplateController.php | 27 +++++++++ app/Http/routes.php | 4 ++ resources/views/templates/listing.blade.php | 55 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 app/Http/Controllers/Admin/TemplateController.php create mode 100644 resources/views/templates/listing.blade.php diff --git a/app/Http/Controllers/Admin/TemplateController.php b/app/Http/Controllers/Admin/TemplateController.php new file mode 100644 index 000000000..fb50d0808 --- /dev/null +++ b/app/Http/Controllers/Admin/TemplateController.php @@ -0,0 +1,27 @@ +getAll(); + + return view('templates.listing', [ + 'title' => Lang::get('templates.manage'), + 'templates' => $templates->toJson() // Because PresentableInterface toJson() is not working in the view + ]); + } +} \ No newline at end of file diff --git a/app/Http/routes.php b/app/Http/routes.php index 54bffab56..a831efb49 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -60,6 +60,10 @@ Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () { + Route::resource('templates', 'TemplateController', [ + 'only' => ['index', 'store', 'update', 'destroy'] + ]); + Route::resource('projects', 'ProjectController', [ 'only' => ['index', 'store', 'update', 'destroy'] ]); diff --git a/resources/views/templates/listing.blade.php b/resources/views/templates/listing.blade.php new file mode 100644 index 000000000..9a898281b --- /dev/null +++ b/resources/views/templates/listing.blade.php @@ -0,0 +1,55 @@ +@extends('layout') + +@section('content') +
+ +
+

{{ Lang::get('templates.none') }}

+
+ +
+ + + + + + + + + + + +
{{ Lang::get('templates.name') }}{{ Lang::get('templates.commands') }} 
+
+
+ + + + + + +@stop + +@section('javascript') + +@stop + +@section('right-buttons') +
+ +
+@stop \ No newline at end of file From 8e8f87e5082187c3c12cac16f2a4e9da90b7c7f4 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Tue, 16 Jun 2015 23:19:49 +0100 Subject: [PATCH 12/66] Start on managing templates --- app/Project.php | 11 -- .../EloquentTemplateRepository.php | 6 +- app/Template.php | 59 ++++++++++ gulpfile.js | 1 + resources/assets/js/projects.js | 2 - resources/assets/js/templates.js | 104 ++++++++++++++++++ resources/views/templates/listing.blade.php | 8 +- 7 files changed, 171 insertions(+), 20 deletions(-) create mode 100644 app/Template.php create mode 100644 resources/assets/js/templates.js diff --git a/app/Project.php b/app/Project.php index ed3afd029..ae1c2e10c 100644 --- a/app/Project.php +++ b/app/Project.php @@ -264,17 +264,6 @@ public function getWebhookUrlAttribute() return route('webhook', $this->hash); } - /** - * Query scope to only show templates - * - * @param object $query - * @return object - */ - public function scopeTemplates($query) - { - return $query->where('is_template', '=', true); - } - /** * Query scope to not show templates * diff --git a/app/Repositories/EloquentTemplateRepository.php b/app/Repositories/EloquentTemplateRepository.php index 93345974d..dbbaf38fb 100644 --- a/app/Repositories/EloquentTemplateRepository.php +++ b/app/Repositories/EloquentTemplateRepository.php @@ -2,7 +2,7 @@ namespace App\Repositories; -use App\Project; +use App\Template; use App\Repositories\Contracts\TemplateRepositoryInterface; /** @@ -13,10 +13,10 @@ class EloquentTemplateRepository extends EloquentRepository implements TemplateR /** * Class constructor. * - * @param Project $model + * @param Template $model * @return EloquentProjectRepository */ - public function __construct(Project $model) + public function __construct(Template $model) { $this->model = $model; } diff --git a/app/Template.php b/app/Template.php new file mode 100644 index 000000000..9f60efb58 --- /dev/null +++ b/app/Template.php @@ -0,0 +1,59 @@ +where('is_template', '=', true); + } + + /** + * Define a accessor for the count of projects. + * + * @return int + */ + public function getCommandCountAttribute() + { + return $this->commands() + ->count(); + } + + /** + * Has many relationship. + * + * @return Command + */ + public function commands() + { + return $this->hasMany('App\Command', 'project_id'); + } +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 68b70416a..d8b2209c3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -62,6 +62,7 @@ elixir(function(mix) { .scripts([ 'app.js', 'projects.js', + 'templates.js', 'servers.js', 'heartbeats.js', 'notifications.js', diff --git a/resources/assets/js/projects.js b/resources/assets/js/projects.js index 5c373321e..8d4f2396b 100644 --- a/resources/assets/js/projects.js +++ b/resources/assets/js/projects.js @@ -214,8 +214,6 @@ var app = app || {}; app.Projects.remove(project); } - console.log(data); - $('#project_' + data.model.id).parent('li').remove(); if (parseInt(data.model.id) === parseInt(app.project_id)) { diff --git a/resources/assets/js/templates.js b/resources/assets/js/templates.js new file mode 100644 index 000000000..081fe2322 --- /dev/null +++ b/resources/assets/js/templates.js @@ -0,0 +1,104 @@ +var app = app || {}; + +(function ($) { + + app.Template = Backbone.Model.extend({ + urlRoot: '/admin/templates' + }); + + var Templates = Backbone.Collection.extend({ + model: app.Template + }); + + app.Templates = new Templates(); + + app.TemplatesTab = Backbone.View.extend({ + el: '#app', + events: { + + }, + initialize: function() { + this.$list = $('#template_list tbody'); + + $('#template_list').hide(); + $('#no_templates').show(); + + this.listenTo(app.Templates, 'add', this.addOne); + this.listenTo(app.Templates, 'reset', this.addAll); + this.listenTo(app.Templates, 'remove', this.addAll); + this.listenTo(app.Templates, 'all', this.render); + + app.listener.on('template:App\\Events\\ModelChanged', function (data) { + var template = app.Templates.get(parseInt(data.model.id)); + + if (template) { + template.set(data.model); + } + }); + + app.listener.on('template:App\\Events\\ModelCreated', function (data) { + app.Templates.add(data.model); + }); + + app.listener.on('template:App\\Events\\ModelTrashed', function (data) { + var template = app.Templates.get(parseInt(data.model.id)); + + if (template) { + app.Templates.remove(template); + } + }); + }, + render: function () { + if (app.Templates.length) { + $('#no_templates').hide(); + $('#template_list').show(); + } else { + $('#no_templates').show(); + $('#template_list').hide(); + } + }, + addOne: function (template) { + var view = new app.TemplateView({ + model: template + }); + + this.$list.append(view.render().el); + }, + addAll: function () { + this.$list.html(''); + app.Templates.each(this.addOne, this); + } + }); + + app.TemplateView = Backbone.View.extend({ + tagName: 'tr', + events: { + 'click .btn-edit': 'editTemplate' + }, + initialize: function () { + this.listenTo(this.model, 'change', this.render); + this.listenTo(this.model, 'destroy', this.remove); + + this.template = _.template($('#template-template').html()); + }, + render: function () { + var data = this.model.toJSON(); + + this.$el.html(this.template(data)); + + return this; + }, + editTemplate: function() { + /* + $('#project_id').val(this.model.id); + $('#project_name').val(this.model.get('name')); + $('#project_repository').val(this.model.get('repository')); + $('#project_branch').val(this.model.get('branch')); + $('#project_group_id').val(this.model.get('group_id')); + $('#project_builds_to_keep').val(this.model.get('builds_to_keep')); + $('#project_url').val(this.model.get('url')); + $('#project_build_url').val(this.model.get('build_url')); + */ + } + }); +})(jQuery); \ No newline at end of file diff --git a/resources/views/templates/listing.blade.php b/resources/views/templates/listing.blade.php index 9a898281b..426995923 100644 --- a/resources/views/templates/listing.blade.php +++ b/resources/views/templates/listing.blade.php @@ -25,9 +25,9 @@ - @stop From f4c30213a39e1d5d1e7971e03da1c8d5b9f124f9 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 10:04:46 +0100 Subject: [PATCH 13/66] Fixing PHPCI issues --- app/Http/Controllers/Admin/TemplateController.php | 5 ++++- app/Jobs/SetupProject.php | 4 ++-- app/Project.php | 5 +++-- app/Template.php | 9 ++++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Admin/TemplateController.php b/app/Http/Controllers/Admin/TemplateController.php index fb50d0808..b2eae7a0c 100644 --- a/app/Http/Controllers/Admin/TemplateController.php +++ b/app/Http/Controllers/Admin/TemplateController.php @@ -7,6 +7,9 @@ use App\Repositories\Contracts\TemplateRepositoryInterface; use Lang; +/** + * Controller for managing deployment template + */ class TemplateController extends Controller { /** @@ -24,4 +27,4 @@ public function index(TemplateRepositoryInterface $templateRepository) 'templates' => $templates->toJson() // Because PresentableInterface toJson() is not working in the view ]); } -} \ No newline at end of file +} diff --git a/app/Jobs/SetupProject.php b/app/Jobs/SetupProject.php index 1b9ee12ca..cf3052fbc 100644 --- a/app/Jobs/SetupProject.php +++ b/app/Jobs/SetupProject.php @@ -37,8 +37,8 @@ public function handle() { $template = Project::findOrFail($this->template_id); - foreach ($template->commands as $command) { - + foreach ($template->commands as $command) + { $data = $command->toArray(); $data['project_id'] = $this->project->id; diff --git a/app/Project.php b/app/Project.php index ae1c2e10c..daf3d5ac3 100644 --- a/app/Project.php +++ b/app/Project.php @@ -38,7 +38,8 @@ class Project extends ProjectRelation implements PresentableInterface * * @var array */ - protected $fillable = ['name', 'repository', 'branch', 'group_id', 'builds_to_keep', 'url', 'build_url', 'is_template']; + protected $fillable = ['name', 'repository', 'branch', 'group_id', + 'builds_to_keep', 'url', 'build_url', 'is_template']; /** * The fields which should be treated as Carbon instances. @@ -266,7 +267,7 @@ public function getWebhookUrlAttribute() /** * Query scope to not show templates - * + * * @param object $query * @return object */ diff --git a/app/Template.php b/app/Template.php index 9f60efb58..1ee61e18c 100644 --- a/app/Template.php +++ b/app/Template.php @@ -2,11 +2,14 @@ namespace App; +/** + * Model for templates + */ class Template extends Project { /** * Fields to show in the JSON presentation - * + * * @var array */ protected $visible = ['name', 'command_count']; @@ -27,7 +30,7 @@ class Template extends Project /** * Query scope to only show templates - * + * * @param object $query * @return object */ @@ -56,4 +59,4 @@ public function commands() { return $this->hasMany('App\Command', 'project_id'); } -} \ No newline at end of file +} From f8a59be7b65d886dc5ab98ec620b522041de18d0 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 10:10:07 +0100 Subject: [PATCH 14/66] Fixing a PHPCS issue --- app/Jobs/SetupProject.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Jobs/SetupProject.php b/app/Jobs/SetupProject.php index cf3052fbc..6ab3da7b0 100644 --- a/app/Jobs/SetupProject.php +++ b/app/Jobs/SetupProject.php @@ -37,8 +37,7 @@ public function handle() { $template = Project::findOrFail($this->template_id); - foreach ($template->commands as $command) - { + foreach ($template->commands as $command) { $data = $command->toArray(); $data['project_id'] = $this->project->id; From d07fa39a57eadd159624aec90645c3d37c4158c4 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 14:05:01 +0100 Subject: [PATCH 15/66] Cleaning up unneeded use statements --- app/Http/Controllers/Admin/TemplateController.php | 1 - database/seeds/TemplateSeeder.php | 1 - 2 files changed, 2 deletions(-) diff --git a/app/Http/Controllers/Admin/TemplateController.php b/app/Http/Controllers/Admin/TemplateController.php index b2eae7a0c..5007a85b1 100644 --- a/app/Http/Controllers/Admin/TemplateController.php +++ b/app/Http/Controllers/Admin/TemplateController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; -use App\Http\Requests; use App\Repositories\Contracts\TemplateRepositoryInterface; use Lang; diff --git a/database/seeds/TemplateSeeder.php b/database/seeds/TemplateSeeder.php index fb05d79c0..1d46368d5 100644 --- a/database/seeds/TemplateSeeder.php +++ b/database/seeds/TemplateSeeder.php @@ -3,7 +3,6 @@ use App\Command; use App\Project; use Illuminate\Database\Seeder; -use Illuminate\Database\Eloquent\Model; class TemplateSeeder extends Seeder { From 2e3f7a66a642ca34335198932e9de1c11a07d6cf Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 17:23:56 +0100 Subject: [PATCH 16/66] Create LICENSING.md --- LICENSING.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSING.md diff --git a/LICENSING.md b/LICENSING.md new file mode 100644 index 000000000..b8bebdf6c --- /dev/null +++ b/LICENSING.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Stephen Ball + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. From 1c525c09e2e6d9479989bab669426691a0417057 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 17:24:38 +0100 Subject: [PATCH 17/66] Update LICENSING.md --- LICENSING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LICENSING.md b/LICENSING.md index b8bebdf6c..6326f1de9 100644 --- a/LICENSING.md +++ b/LICENSING.md @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 8fd1744238845b691935f1971114a08c973fcdec Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 17:26:04 +0100 Subject: [PATCH 18/66] Rename LICENSING.md to LICENSE.md --- LICENSING.md => LICENSE.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSING.md => LICENSE.md (100%) diff --git a/LICENSING.md b/LICENSE.md similarity index 100% rename from LICENSING.md rename to LICENSE.md From 8696a6d2561574fffd2516fcbfeda6ade50a200d Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 17:26:26 +0100 Subject: [PATCH 19/66] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 678341b1f..289ad5dbd 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ [![PHP Dependency Status](https://www.versioneye.com/user/projects/5531329410e7141211000f29/badge.svg)](https://www.versioneye.com/user/projects/5531329410e7141211000f29) [![Nodge Dependency Status](https://www.versioneye.com/user/projects/5531329610e714f9e500109c/badge.svg)](https://www.versioneye.com/user/projects/5531329610e714f9e500109c) [![Latest Version](https://img.shields.io/github/release/REBELinBLUE/deployer.svg)](https://github.com/REBELinBLUE/deployer/releases) +[![License](https://img.shields.io/github/license/rebelinblue/deployer.svg)](https://github.com/REBELinBLUE/deployer/blob/master/LICENSE.md) **Development** From b77774ffb5d36fc55ad818fefff944e331d2b130 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:10:55 +0100 Subject: [PATCH 20/66] Create .travis.yml --- .travis.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..20d574b37 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: php + +php: + - 5.5.9 + - 5.5 + - 5.6 + - 7.0 + - hhvm + +install: + - composer install --no-interaction --prefer-source + - npm install + - bower install From a3c898f65dea7f12f9b69d16745f9e4f8445282f Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:22:51 +0100 Subject: [PATCH 21/66] Update .travis.yml --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 20d574b37..e26ec7f3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,12 @@ php: - 7.0 - hhvm +before_script: + - npm install -g grunt-cli + - npm install -g bower + - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config + - bower install -f + install: - composer install --no-interaction --prefer-source - npm install From b868533fd23711dc48b380ed8c16cc55fdf76ef1 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:26:35 +0100 Subject: [PATCH 22/66] Update .travis.yml --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index e26ec7f3c..ba9ebe526 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,14 @@ install: - composer install --no-interaction --prefer-source - npm install - bower install + +matrix: + allow_failures: + - php: 7.0 + - php: hhvm + fast_finish: true + +# Customize when the notification emails are sent. +notifications: + on_success: never + on_failure: always From 32da48bbf2bd4f3a34c50e628662ace2e03d7f7c Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:26:49 +0100 Subject: [PATCH 23/66] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ba9ebe526..0683be864 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ php: - hhvm before_script: + - composer self-update - npm install -g grunt-cli - npm install -g bower - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config From 595b98730a4d3d7c0a0da7507ae1846657460fd2 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:27:40 +0100 Subject: [PATCH 24/66] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0683be864..d81402985 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ php: - 7.0 - hhvm -before_script: +before_install: - composer self-update - npm install -g grunt-cli - npm install -g bower From d7be0b11c4d8577c6197ccdf077c20ff4528b058 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:39:34 +0100 Subject: [PATCH 25/66] Update .travis.yml --- .travis.yml | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index d81402985..063a95755 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,17 +8,28 @@ php: - hhvm before_install: - - composer self-update - - npm install -g grunt-cli - - npm install -g bower + - travis_retry composer self-update + - travis_retry npm install -g grunt-cli + - travis_retry npm install -g bower - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config - - bower install -f + - travis_retry bower install -f install: - - composer install --no-interaction --prefer-source - - npm install - - bower install + - travis_retry composer install --no-interaction --prefer-source + - travis_retry npm install + - travis_retry bower install +before_script: + - chmod -R 777 storage + - touch storage/database.sqlite + +script: + - php artisan migrate:refresh --no-interaction -vvv --seed + +after_script: + - ls -laR storage + - cat storage/logs/* + matrix: allow_failures: - php: 7.0 From 320e07e21a01cecb5c2953c8739284473d12ce0e Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:47:02 +0100 Subject: [PATCH 26/66] Update .travis.yml --- .travis.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 063a95755..e57a7b83d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,17 @@ php: - 5.6 - 7.0 - hhvm - + +env: + global: + - APP_ENV=testing + - APP_DEBUG=true + - APP_TIMEZONE=Europe/London + - APP_KEY=cHKwVTJCF75DKo9bta72ZNrkS6Q0tqYy + - CACHE_DRIVER=array + - SESSION_DRIVER=array + - QUEUE_DRIVER=sync + before_install: - travis_retry composer self-update - travis_retry npm install -g grunt-cli @@ -15,7 +25,7 @@ before_install: - travis_retry bower install -f install: - - travis_retry composer install --no-interaction --prefer-source + - travis_retry composer install --no-interaction --prefer-dist - travis_retry npm install - travis_retry bower install From 30bb10b00a472c9b2bbad69a14730287fb04adcd Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 20:54:05 +0100 Subject: [PATCH 27/66] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e57a7b83d..ea8048007 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ env: - CACHE_DRIVER=array - SESSION_DRIVER=array - QUEUE_DRIVER=sync + - BROADCAST_DRIVER=log before_install: - travis_retry composer self-update From 2b98b7d836561224d59f9f63ba0084cbc395c980 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 21:30:36 +0100 Subject: [PATCH 28/66] Tweaking migrations so they continue to work --- .../migrations/2015_03_15_155553_create_groups_table.php | 6 ------ .../migrations/2015_03_16_212800_create_projects_table.php | 6 ++++++ .../migrations/2015_05_07_145127_change_output_column.php | 4 ++-- phpunit.xml | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/database/migrations/2015_03_15_155553_create_groups_table.php b/database/migrations/2015_03_15_155553_create_groups_table.php index 165336fc6..df8965c8b 100644 --- a/database/migrations/2015_03_15_155553_create_groups_table.php +++ b/database/migrations/2015_03_15_155553_create_groups_table.php @@ -3,8 +3,6 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -use App\Group; - class CreateGroupsTable extends Migration { /** @@ -20,10 +18,6 @@ public function up() $table->timestamps(); $table->softDeletes(); }); - - Group::create([ - 'name' => 'Projects' - ]); } /** diff --git a/database/migrations/2015_03_16_212800_create_projects_table.php b/database/migrations/2015_03_16_212800_create_projects_table.php index 6ac2b8904..09dbdba19 100644 --- a/database/migrations/2015_03_16_212800_create_projects_table.php +++ b/database/migrations/2015_03_16_212800_create_projects_table.php @@ -1,5 +1,6 @@ softDeletes(); $table->foreign('group_id')->references('id')->on('groups'); }); + + // Had to move this from the previous migration due to group having an attribute for project count + Group::create([ + 'name' => 'Projects' + ]); } /** diff --git a/database/migrations/2015_05_07_145127_change_output_column.php b/database/migrations/2015_05_07_145127_change_output_column.php index 5012d712d..1ae1866c0 100644 --- a/database/migrations/2015_05_07_145127_change_output_column.php +++ b/database/migrations/2015_05_07_145127_change_output_column.php @@ -11,7 +11,7 @@ class ChangeOutputColumn extends Migration */ public function up() { - if ($_ENV['DB_TYPE'] != 'sqlite') { + if (isset($_ENV['DB_TYPE']) && $_ENV['DB_TYPE'] != 'sqlite') { DB::statement('ALTER TABLE server_logs CHANGE output output longtext'); } } @@ -23,7 +23,7 @@ public function up() */ public function down() { - if ($_ENV['DB_TYPE'] != 'sqlite') { + if (isset($_ENV['DB_TYPE']) && $_ENV['DB_TYPE'] != 'sqlite') { DB::statement('ALTER TABLE server_logs CHANGE output output text'); } } diff --git a/phpunit.xml b/phpunit.xml index dd197d071..ca4a41514 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -25,5 +25,6 @@ + \ No newline at end of file From 1244daca3d29da93dd085a35c90eff263e4456f8 Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 21:37:54 +0100 Subject: [PATCH 29/66] Delete .travis.yml --- .travis.yml | 53 ----------------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ea8048007..000000000 --- a/.travis.yml +++ /dev/null @@ -1,53 +0,0 @@ -language: php - -php: - - 5.5.9 - - 5.5 - - 5.6 - - 7.0 - - hhvm - -env: - global: - - APP_ENV=testing - - APP_DEBUG=true - - APP_TIMEZONE=Europe/London - - APP_KEY=cHKwVTJCF75DKo9bta72ZNrkS6Q0tqYy - - CACHE_DRIVER=array - - SESSION_DRIVER=array - - QUEUE_DRIVER=sync - - BROADCAST_DRIVER=log - -before_install: - - travis_retry composer self-update - - travis_retry npm install -g grunt-cli - - travis_retry npm install -g bower - - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config - - travis_retry bower install -f - -install: - - travis_retry composer install --no-interaction --prefer-dist - - travis_retry npm install - - travis_retry bower install - -before_script: - - chmod -R 777 storage - - touch storage/database.sqlite - -script: - - php artisan migrate:refresh --no-interaction -vvv --seed - -after_script: - - ls -laR storage - - cat storage/logs/* - -matrix: - allow_failures: - - php: 7.0 - - php: hhvm - fast_finish: true - -# Customize when the notification emails are sent. -notifications: - on_success: never - on_failure: always From 621ddd128ee152e26f1fef98aadf4be30e35856d Mon Sep 17 00:00:00 2001 From: Stephen Ball Date: Wed, 17 Jun 2015 23:05:42 +0100 Subject: [PATCH 30/66] Changing icon for logs --- resources/views/dialogs/log.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/dialogs/log.blade.php b/resources/views/dialogs/log.blade.php index 5c31f28e3..553b5ea63 100644 --- a/resources/views/dialogs/log.blade.php +++ b/resources/views/dialogs/log.blade.php @@ -3,7 +3,7 @@ +
+ +
+ +
+