Skip to content

Commit 545dbcf

Browse files
committed
Before and after pull event commands added
1 parent d4dbf9e commit 545dbcf

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,21 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
66

77
## [UNRELEASED]
88

9+
## [0.0.1.6] - 2017-03-05
10+
### Changed
11+
- Payload management improved
12+
- Configuration description extended
13+
14+
### Added
15+
- After pull event commands option added
16+
- Before pull event command option added
17+
18+
## [0.0.1.1 - 0.0.1.5] - 2017-03-05
19+
### Added
20+
- GitHook Service moved into different classes
21+
- Github Payload support added
22+
- Bitbucket Payload support added
23+
24+
## 0.0.1 - 2017-03-04
925
### Added
1026
- new laravel-git-hook package

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Custom configuration can be made within the `config/git-hook.php` file:
5151
| logfile | git-hook | | Name of the logfile. It will be stored under storage/logs |
5252
| service | github | `github`, `gitbucket` | Define your remote git service. This is required to identify the payload |
5353
| url | git-hook | | Define the deployment url. Keep in mind, that the given parameter will be added to your app.url |
54+
| before_pull | [] | ['route:clear', ['some:command', ['arg1' => 1]]] | If you have any commands that have to be called before a pull event, specify them here |
55+
| after_pull | [] | ['route:clear', ['some:command', ['arg1' => 1]]] | If you have any commands that have to be called after a pull event, specify them here |
5456

5557

5658
If you are concerned someone could guess it, use a more cryptic url such as: `JHFUjhd67567JHFGhsd78236784wegfJHFghdgf`

src/GitHook/GitHook.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Webklex\GitHook;
1515

16+
use Illuminate\Support\Facades\Artisan;
1617
use Monolog\Logger;
1718
use Monolog\Handler\StreamHandler;
1819
use Webklex\GitHook\Payload\Payload;
@@ -94,8 +95,6 @@ public function getLogger(){
9495
* @return bool
9596
*/
9697
public function parseRequest($rawRequest){
97-
$this->aRequest = collect(json_decode($rawRequest, true));
98-
9998
$service = 'Webklex\GitHook\Payload\Services\\'.ucfirst($this->config['service']).'Service';
10099

101100
/***
@@ -193,6 +192,25 @@ public function checkBranch(){
193192
return $this->getCurrentBranch() == $this->pushedBranch;
194193
}
195194

195+
/**
196+
* Run an array of given commands
197+
* @param array $commands
198+
*/
199+
protected function runCommands(array $commands){
200+
foreach($commands as $command){
201+
202+
$cmd = $command;
203+
$args = [];
204+
205+
if(is_array($command)){
206+
$cmd = $command[0];
207+
$args = $command[1];
208+
}
209+
210+
Artisan::call($cmd, $args);
211+
}
212+
}
213+
196214
/**
197215
* Perform the deployment task
198216
*
@@ -208,10 +226,16 @@ public function gitPull(){
208226
escapeshellarg($this->getCurrentBranch()) . ' >> ' .
209227
escapeshellarg($this->config['repo_path'] . '/storage/logs/git-hook.log');
210228

229+
$this->runCommands($this->config['before_pull']);
230+
231+
$pullRequest = shell_exec($cmd);
232+
233+
$this->runCommands($this->config['after_pull']);
234+
211235
return $this->notify([
212236
'cmd' => $cmd,
213237
'user' => shell_exec('whoami'),
214-
'response' => shell_exec($cmd),
238+
'response' => $pullRequest,
215239
]);
216240
}
217241

src/config/git-hook.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,35 @@
139139
| It will be transformed into: https://your-domain.tld/another-git-hook
140140
|
141141
*/
142-
'url' => 'git-hook'
142+
'url' => 'git-hook',
143+
144+
145+
/*
146+
|--------------------------------------------------------------------------
147+
| Before pull event
148+
|--------------------------------------------------------------------------
149+
|
150+
| If you have any commands that have to be called before a pull event, specify
151+
| them below.
152+
|
153+
| ['route:clear', ['some:command', ['arg1' => 1]]]
154+
|
155+
*/
156+
'before_pull' => [],
157+
158+
159+
/*
160+
|--------------------------------------------------------------------------
161+
| After pull event
162+
|--------------------------------------------------------------------------
163+
|
164+
| If you have any commands that have to be called after a pull event, specify
165+
| them below.
166+
|
167+
| ['route:clear', ['some:command', ['arg1' => 1]]]
168+
|
169+
*/
170+
'after_pull' => []
143171

144172

145173
];

0 commit comments

Comments
 (0)