Skip to content

Commit 68c7a12

Browse files
committed
Structure updateed | Error logging extended
1 parent c5936a8 commit 68c7a12

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/GitHook/GitHook.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ class GitHook {
4848
*/
4949
protected $currentBranch = null;
5050

51+
/**
52+
* This variable might be set and used later on. It holds the pushed branch name
53+
* @var null
54+
*/
55+
protected $pushedBranch = null;
56+
5157
/**
5258
* GitHook constructor.
5359
*/
@@ -119,7 +125,7 @@ public function locateLaravelRoot(){
119125
*
120126
* @return string
121127
*/
122-
protected function getCurrentBranch(){
128+
public function getCurrentBranch(){
123129
if($this->currentBranch == null){
124130
$this->currentBranch = trim(
125131
shell_exec(
@@ -131,6 +137,15 @@ protected function getCurrentBranch(){
131137
return $this->currentBranch;
132138
}
133139

140+
/**
141+
* Get the pushed branch name
142+
*
143+
* @return string
144+
*/
145+
public function getPushedBranch(){
146+
return $this->pushedBranch;
147+
}
148+
134149
/**
135150
* Check if white listing is enabled and if so if the request comes from a white listed IP
136151
*
@@ -163,10 +178,10 @@ public function checkRepository(){
163178
* @return bool
164179
*/
165180
public function checkBranch(){
166-
$pushed_branch = explode('/', $this->aRequest->get('ref'));
167-
$pushed_branch = trim($pushed_branch[2]);
181+
$pushedBranch = explode('/', $this->aRequest->get('ref'));
182+
$this->pushedBranch = trim($pushedBranch[2]);
168183

169-
return $this->getCurrentBranch() == $pushed_branch;
184+
return $this->getCurrentBranch() == $this->pushedBranch;
170185
}
171186

172187
/**

src/GitHook/Http/Controller/GitHookController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function gitHook(Request $request)
7878
/* Check if the pushed branch is the one we one want to deploy
7979
* */
8080
if ($this->oGitHook->checkBranch() == false){
81-
$this->oGitHook->getLogger()->addWarning('Pushed refs do not match current branch');
81+
$this->oGitHook->getLogger()->addWarning('Pushed refs do not match current branch: ['.
82+
$this->oGitHook->getCurrentBranch().' /=/ '.$this->oGitHook->getPushedBranch().']');
8283
return response()->json([
8384
'success' => false,
8485
'message' => 'Pushed refs do not match current branch',

src/GitHook/Providers/LaravelServiceProvider.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ public function boot()
2626
$this->publishes([
2727
__DIR__.'/../../config/git-hook.php' => config_path('git-hook.php'),
2828
]);
29-
$this->loadViewsFrom(__DIR__.'/../resources/views', 'git-hook');
3029

31-
$source = realpath(__DIR__.'/../../config/git-hook.php');
32-
$this->mergeConfigFrom($source, 'git-hook');
30+
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/git-hook.php'), 'git-hook');
31+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'git-hook');
3332

3433
require __DIR__.'/../Http/routes.php';
3534
}
@@ -42,7 +41,7 @@ public function boot()
4241
public function register()
4342
{
4443
$this->app->bind('git-hook', function ($app) {
45-
//return new GitHookApp;
44+
return new GitHookApp;
4645
});
4746

4847
}

0 commit comments

Comments
 (0)