Skip to content

Commit 60e30fc

Browse files
committed
git diff
1 parent 6dc3a46 commit 60e30fc

File tree

18 files changed

+267
-62
lines changed

18 files changed

+267
-62
lines changed

app/GitInteractions/Git.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,25 @@ function deployGit() {
132132
$response->name = 'clone into release folder using the mirror repository';
133133
$response->success = (strpos($response->message,'git clone created') === false) ? 0 : 1;
134134
$this->responses->push($response);
135+
}
135136

137+
/**
138+
* @param $commitRef string
139+
* @return string
140+
*/
141+
public function getGitDiff(string $commitRef)
142+
{
143+
$cmd = <<<'BASH'
144+
function gitDiff() {
145+
local deployLocation="${1}";
146+
local commitRef="${2}";
147+
cd ${deployLocation}/current
148+
$(git pull origin master)
149+
git diff --name-only $commitRef
150+
}
151+
BASH;
152+
$cmd .= "\n gitDiff {$this->server->deploy_location} {$commitRef}";
153+
$response = $this->connection->execute($cmd);
154+
return $response->message;
136155
}
137156
}

app/Http/Controllers/DeploymentController.php

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public function __construct()
2020
/**
2121
* Display a listing of the resource.
2222
*
23-
* @return \Illuminate\Http\Response
23+
* @param Project $project
24+
* @param Server $server
25+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
2426
*/
2527
public function index(Project $project, Server $server)
2628
{
@@ -81,37 +83,62 @@ public function show(Project $project,Server $server,Deployment $deployment)
8183
return view('deployments.show', compact('project','server', 'deployment'));
8284
}
8385

84-
/**
85-
* Show the form for editing the specified resource.
86-
*
87-
* @param \App\Deployment $deployment
88-
* @return \Illuminate\Http\Response
89-
*/
90-
public function edit(Deployment $deployment)
91-
{
92-
//
93-
}
86+
// /**
87+
// * Show the form for editing the specified resource.
88+
// *
89+
// * @param \App\Deployment $deployment
90+
// * @return \Illuminate\Http\Response
91+
// */
92+
// public function edit(Deployment $deployment)
93+
// {
94+
// //
95+
// }
96+
//
97+
// /**
98+
// * Update the specified resource in storage.
99+
// *
100+
// * @param \Illuminate\Http\Request $request
101+
// * @param \App\Deployment $deployment
102+
// * @return \Illuminate\Http\Response
103+
// */
104+
// public function update(Request $request, Deployment $deployment)
105+
// {
106+
// //
107+
// }
108+
//
109+
// /**
110+
// * Remove the specified resource from storage.
111+
// *
112+
// * @param \App\Deployment $deployment
113+
// * @return \Illuminate\Http\Response
114+
// */
115+
// public function destroy(Deployment $deployment)
116+
// {
117+
// //
118+
// }
94119

95120
/**
96-
* Update the specified resource in storage.
121+
* Show git diff
97122
*
98-
* @param \Illuminate\Http\Request $request
99-
* @param \App\Deployment $deployment
100-
* @return \Illuminate\Http\Response
123+
* @param Project $project
124+
* @param Server $server
125+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
101126
*/
102-
public function update(Request $request, Deployment $deployment)
127+
public function gitDiff(Project $project,Server $server)
103128
{
104-
//
129+
$gitDiff = [];
130+
$commitRef = request('commit');
131+
$connection = new SshConnection($server->toArray());
132+
$response = $connection->connect();
133+
if ($response['success'] != 0 ) {
134+
$git = new Git(
135+
$connection,
136+
$server
137+
);
138+
$gitDiff = $git->getGitDiff($commitRef);
139+
}
140+
return view('deployments.gitDiff',compact('server','project', 'commitRef', 'gitDiff'));
105141
}
106142

107-
/**
108-
* Remove the specified resource from storage.
109-
*
110-
* @param \App\Deployment $deployment
111-
* @return \Illuminate\Http\Response
112-
*/
113-
public function destroy(Deployment $deployment)
114-
{
115-
//
116-
}
143+
117144
}

docker/dev/setup_test_laravel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cat /home/www-data/.ssh/id_rsa.pub >> /code/deploy-target/.ssh/authorized_keys
66
# setup laravel
77
apache2ctl restart
88
chgrp -R www-data /var/www/html/storage /var/www/html/bootstrap/cache
9-
chmod -R ug+w /var/www/html/storage /var/www/html/bootstrap/cache
9+
chmod -R ug+w /var/www/html/storage /var/www/html/bootstrap/cache /var/www/html/database
1010
composer install --no-interaction --working-dir=/var/www/html
1111

1212
if [[ $(php artisan migrate:status) = *"No migrations found"* ]]; then

docker/dev/tests/RunPhpunitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
chdir('/var/www/html');
2121
$argv[] = 'vendor/bin/phpunit';
2222
$argv[] = '--stop-on-error';
23-
$argv[] = '/var/www/html/tests/functional/ManageDeploymentsTest.php';
24-
$argv[] = '--filter=testAnAuthenticatedUserCanRunADeployment';
23+
$argv[] = '/var/www/html/tests/phpunit/Unit/DeploymentTest.php';
24+
$argv[] = '--filter=testGitDiff';
2525
$argc = count($argv);
2626
$_SERVER['argv'] = $argv;
2727
$_SERVER['argc'] = $argc;

phpunit.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@
2424
</filter>
2525
<php>
2626
<env name="APP_ENV" value="testing"/>
27+
<env name="APP_KEY" value="base64:4DUm9wLmfFPFzbMeIBNKB/rg5ANfaiCfK2I18kUFgHU="/>
2728
<env name="BCRYPT_ROUNDS" value="4"/>
2829
<env name="CACHE_DRIVER" value="array"/>
2930
<env name="SESSION_DRIVER" value="array"/>
3031
<env name="QUEUE_DRIVER" value="sync"/>
3132
<env name="MAIL_DRIVER" value="array"/>
32-
<!--env name="DB_CONNECTION" value="sqlite"/-->
33-
<!--env name="DB_NAME" value=":memory:"/-->
34-
<env name="DB_CONNECTION" value="mysql"/>
35-
<env name="DB_HOST" value="version_deployment_unit_test_db"/>
36-
<env name="DB_PORT" value="3306"/>
37-
<env name="DB_DATABASE" value="deploy_unit_test"/>
38-
<env name="DB_USERNAME" value="devuser"/>
39-
<env name="DB_PASSWORD" value="devpass"/>
33+
<env name="DB_CONNECTION" value="sqlite"/>
34+
<env name="DB_NAME" value=":memory:"/>
35+
<!--env name="DB_CONNECTION" value="mysql"/-->
36+
<!--env name="DB_HOST" value="version_deployment_unit_test_db"/-->
37+
<!--env name="DB_PORT" value="3306"/-->
38+
<!--env name="DB_DATABASE" value="deploy_unit_test"/-->
39+
<!--env name="DB_USERNAME" value="devuser"/-->
40+
<!--env name="DB_PASSWORD" value="devpass"/-->
4041
</php>
4142
</phpunit>

resources/views/deployments/create.blade.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,34 @@
77
<div class="card">
88
<div class="card-header">Start Deployment:</div>
99
<div class="card-body">
10-
<div class="name">
11-
<label for="name" >Server</label>
12-
<input name="name" type="text" value="{{$server->name}}" readonly/>
10+
<div class="name form-group row">
11+
<label for="name" class="col-sm-2 col-form-label text-md-right" >Server</label>
12+
<div class="col-sm-10">
13+
<input name="name" class="form-control" type="text" value="{{$server->name}}" readonly/>
14+
</div>
1315
</div>
1416
<hr>
1517
<form method="post" action="{{route('SubmitCreateDeployment',['server'=>$server, 'project'=>$project])}}">
1618
@csrf
1719
<div class="repository form-group row">
18-
<label for="commit" class="col-sm-2 col-form-label">commit:</label>
19-
<select name="commit" class="col-sm-10 form-control form-control-md" id="exampleFormControlSelect1">
20-
@foreach($gitLog as $ref => $text)
21-
<option value="{{$ref}}">{{$text}}</option>
22-
@endforeach
23-
</select>
20+
<label for="commit" class="col-sm-2 col-form-label text-md-right">commit:</label>
21+
<div class="col-sm-10">
22+
<select name="commit" class="form-control form-control-md" id="exampleFormControlSelect1">
23+
@foreach($gitLog as $ref => $text)
24+
<option value="{{$ref}}">{{$text}}</option>
25+
@endforeach
26+
</select>
27+
</div>
2428
</div>
2529
<div class="form-group">
2630
<div class="notes">
2731
<textarea name="notes" class="form-control" placeholder="notes"></textarea>
2832
</div>
2933
</div>
30-
<button type="submit" class="btn btn-default">deploy</button>
34+
<div class="float-right">
35+
<button type="submit" class="btn btn-default">deploy</button>
36+
<button type="submit" class="btn btn-default" formaction="{{route('GitDiffDeployment', ['server'=>$server, 'project'=>$project])}}">git diff</button>
37+
</div>
3138
</form>
3239
</div>
3340
</div>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row justify-content-center">
6+
<div class="col-md-8">
7+
<div class="card">
8+
<div class="card-header">Git Diff:</div>
9+
<div class="card-body">
10+
<div class="name">
11+
<label for="name" >Server</label>
12+
<input name="name" type="text" value="{{$server->name}}" readonly/>
13+
</div>
14+
<hr>
15+
<form method="post" action="{{route('SubmitCreateDeployment',['server'=>$server, 'project'=>$project])}}">
16+
@csrf
17+
<div class="repository form-group row">
18+
<label for="server" class="col-sm-2 col-form-label text-md-right">Server</label>
19+
<div class="col-sm-10">
20+
<input name="server" type="text" value="{{$server->name}}" readonly />
21+
</div>
22+
</div>
23+
<div class="repository form-group row">
24+
<label for="commit" class="col-sm-2 col-form-label text-md-right">Commit</label>
25+
<div class="col-sm-10">
26+
<input name="commit" type="text" value="{{$commitRef}}" readonly/>
27+
</div>
28+
</div>
29+
<div class="gitdiff">
30+
<label for="gitdiff" class="col-form-label">Changed files</label>
31+
<textarea name="gitdiff" class="form-control" readonly>{{$gitDiff}}</textarea>
32+
</div>
33+
<div class="form-group">
34+
<label for="notes" class="col-form-label">Notes</label>
35+
<div class="notes">
36+
<textarea name="notes" class="form-control" placeholder="notes"></textarea>
37+
</div>
38+
</div>
39+
<button type="submit" class="btn btn-default float-right">deploy</button>
40+
</form>
41+
</div>
42+
</div>
43+
</div>
44+
</div>
45+
</div>
46+
@endsection

resources/views/deployments/show.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
<div class="card-body">
1010
<form>
1111
<div class="form-group row">
12-
<label for="name" class="col-sm-2 col-form-label">deployed by:</label>
12+
<label for="name" class="col-sm-2 col-form-label text-md-right">deployed by:</label>
1313
<div class="col-sm-10">
1414
<input type="text" readonly class="form-control" id="name" value="{{$deployment->owner->name}}">
1515
</div>
1616
</div>
1717
<div class="form-group row">
18-
<label for="commit" class="col-sm-2 col-form-label">commit hash:</label>
18+
<label for="commit" class="col-sm-2 col-form-label text-md-right">commit hash:</label>
1919
<div class="col-sm-10">
20-
<input type="text" readonly class="form-control" id="commit" value="{{$deployment->commit}}">
20+
<input type="text" readonly class="form-control" id="commit" value="{{$deployment->commit}}">
2121
</div>
2222
</div>
2323
<div class="form-group row">
24-
<label for="status" class="col-sm-2 col-form-label">status:</label>
24+
<label for="status" class="col-sm-2 col-form-label text-md-right">status:</label>
2525
<div class="col-sm-10">
2626
@if ($deployment->success === 1)
2727
<input type="text" readonly class="form-control status success" id="status" value="success">
@@ -31,9 +31,9 @@
3131
</div>
3232
</div>
3333
<div class="form-group row">
34-
<label for="notes" class="col-sm-2 col-form-label">notes:</label>
34+
<label for="notes" class="col-sm-2 col-form-label text-md-right">notes:</label>
3535
<div class="col-sm-10">
36-
<textarea type="text" readonly class="form-control status success" id="notes">{{$deployment->notes}}</textarea>
36+
<textarea type="text" class="form-control" readonly class="form-control status success" id="notes">{{$deployment->notes}}</textarea>
3737
</div>
3838
</div>
3939
<div>

resources/views/projects/create.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div class="notes">
2222
<textarea name="notes" class="form-control" placeholder="notes" ></textarea>
2323
</div>
24-
<button type="submit" class="btn btn-default">save</button>
24+
<button type="submit" class="btn btn-default float-right">save</button>
2525
</form>
2626
</div>
2727
</div>

resources/views/projects/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<textarea name="notes" class="form-control" placeholder="notes">{{$project->notes}}</textarea>
2424
</div>
2525
</div>
26-
<button type="submit" class="btn btn-default">save</button>
26+
<button type="submit" class="btn btn-default float-right">save</button>
2727
</form>
2828
</div>
2929
</div>

0 commit comments

Comments
 (0)