Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
* master:
  Small copy changes
  Added missing delete option
  Added missing docblock
  Silence PHPMD warning about number of children
  Manage environmental variables.
  Added missing newline
  Clean up some StyleCI violations
  Added UI to manage variables
  Tweak DB seeder
  Adding environmental variables for #133 and #108
  Updated dependencies
  • Loading branch information
REBELinBLUE committed Jan 8, 2016
2 parents d7b08f7 + 779ba4b commit a5c2d8b
Show file tree
Hide file tree
Showing 23 changed files with 614 additions and 75 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/DeploymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function project($project_id)
'sharedFiles' => $project->sharedFiles,
'projectFiles' => $project->projectFiles,
'checkUrls' => $project->checkUrls,
'variables' => $project->variables,
'optional' => $optional,
'route' => 'commands',
]);
Expand Down
56 changes: 56 additions & 0 deletions app/Http/Controllers/Resources/VariableController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace REBELinBLUE\Deployer\Http\Controllers\Resources;

use Illuminate\Support\Facades\Input;
use REBELinBLUE\Deployer\Http\Requests;
use REBELinBLUE\Deployer\Http\Requests\StoreVariableRequest;
use REBELinBLUE\Deployer\Repositories\Contracts\VariableRepositoryInterface;

/**
* Variable management controller.
*/
class VariableController extends ResourceController
{
/**
* Class constructor.
*
* @param VariableRepositoryInterface $repository
* @return void
*/
public function __construct(VariableRepositoryInterface $repository)
{
$this->repository = $repository;
}

/**
* Store a newly created variable in storage.
*
* @param StoreVariableRequest $request
* @return Response
*/
public function store(StoreVariableRequest $request)
{
return $this->repository->create($request->only(
'name',
'value',
'project_id'
));
}

/**
* Update the specified variable in storage.
*
* @param int $variable_id
* @param StoreVariableRequest $request
* @return Response
*/
public function update($variable_id, StoreVariableRequest $request)
{
return $this->repository->updateById($request->only(
'name',
'value',
'project_id'
), $variable_id);
}
}
1 change: 1 addition & 0 deletions app/Http/Requests/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Generic Request class.
* @SuppressWarnings(PHPMD.NumberOfChildren)
*/
abstract class Request extends FormRequest
{
Expand Down
25 changes: 25 additions & 0 deletions app/Http/Requests/StoreVariableRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace REBELinBLUE\Deployer\Http\Requests;

use REBELinBLUE\Deployer\Http\Requests\Request;

/**
* Request for validating variables.
*/
class StoreVariableRequest extends Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|max:255',
'value' => 'required',
'project_id' => 'required|integer|exists:projects,id',
];
}
}
1 change: 1 addition & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
];

Route::resource('servers', 'ServerController', $actions);
Route::resource('variables', 'VariableController', $actions);
Route::resource('commands', 'CommandController', $actions);
Route::resource('heartbeats', 'HeartbeatController', $actions);
Route::resource('notifications', 'NotificationController', $actions);
Expand Down
10 changes: 9 additions & 1 deletion app/Jobs/DeployProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,15 @@ private function getScript(DeployStep $step, Server $server)
$commands = implode(PHP_EOL, $commands);
}

return $commands;
$variables = '';
foreach ($project->variables as $variable) {
$key = $variable->name;
$value = $variable->value;

$variables .= "export {$key}={$value}" . PHP_EOL;
}

return $variables . $commands;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions app/ProjectRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public function commands()
return $this->hasMany('REBELinBLUE\Deployer\Command')->orderBy('order', 'ASC');
}

/**
* Has many relationship.
*
* @return Variable
*/
public function variables()
{
return $this->hasMany('REBELinBLUE\Deployer\Variable');
}

/**
* Has many relationship.
*
Expand Down
1 change: 1 addition & 0 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function register()
$this->bindInterface('SharedFile');
$this->bindInterface('Template');
$this->bindInterface('User');
$this->bindInterface('Variable');
}

/**
Expand Down
11 changes: 11 additions & 0 deletions app/Repositories/Contracts/VariableRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace REBELinBLUE\Deployer\Repositories\Contracts;

interface VariableRepositoryInterface
{
public function getAll();
public function create(array $fields);
public function updateById(array $fields, $model_id);
public function deleteById($model_id);
}
24 changes: 24 additions & 0 deletions app/Repositories/EloquentVariableRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace REBELinBLUE\Deployer\Repositories;

use REBELinBLUE\Deployer\Variable;
use REBELinBLUE\Deployer\Repositories\Contracts\VariableRepositoryInterface;
use REBELinBLUE\Deployer\Repositories\EloquentRepository;

/**
* The variable repository.
*/
class EloquentVariableRepository extends EloquentRepository implements VariableRepositoryInterface
{
/**
* Class constructor.
*
* @param Variable $model
* @return EloquentVariableRepository
*/
public function __construct(Variable $model)
{
$this->model = $model;
}
}
39 changes: 39 additions & 0 deletions app/Variable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace REBELinBLUE\Deployer;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use REBELinBLUE\Deployer\Traits\BroadcastChanges;

/**
* Model for environmental variables.
*/
class Variable extends Model
{
use SoftDeletes, BroadcastChanges;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'value', 'project_id'];

/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];

/**
* Belongs to relationship.
*
* @return Project
*/
public function project()
{
return $this->belongsTo('REBELinBLUE\Deployer\Project');
}
}
Loading

0 comments on commit a5c2d8b

Please sign in to comment.