Skip to content

Commit

Permalink
Before and after pull event commands added
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Mar 5, 2017
1 parent d4dbf9e commit 545dbcf
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,21 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## [UNRELEASED]

## [0.0.1.6] - 2017-03-05
### Changed
- Payload management improved
- Configuration description extended

### Added
- After pull event commands option added
- Before pull event command option added

## [0.0.1.1 - 0.0.1.5] - 2017-03-05
### Added
- GitHook Service moved into different classes
- Github Payload support added
- Bitbucket Payload support added

## 0.0.1 - 2017-03-04
### Added
- new laravel-git-hook package
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Custom configuration can be made within the `config/git-hook.php` file:
| logfile | git-hook | | Name of the logfile. It will be stored under storage/logs |
| service | github | `github`, `gitbucket` | Define your remote git service. This is required to identify the payload |
| url | git-hook | | Define the deployment url. Keep in mind, that the given parameter will be added to your app.url |
| 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 |
| 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 |


If you are concerned someone could guess it, use a more cryptic url such as: `JHFUjhd67567JHFGhsd78236784wegfJHFghdgf`
Expand Down
30 changes: 27 additions & 3 deletions src/GitHook/GitHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Webklex\GitHook;

use Illuminate\Support\Facades\Artisan;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Webklex\GitHook\Payload\Payload;
Expand Down Expand Up @@ -94,8 +95,6 @@ public function getLogger(){
* @return bool
*/
public function parseRequest($rawRequest){
$this->aRequest = collect(json_decode($rawRequest, true));

$service = 'Webklex\GitHook\Payload\Services\\'.ucfirst($this->config['service']).'Service';

/***
Expand Down Expand Up @@ -193,6 +192,25 @@ public function checkBranch(){
return $this->getCurrentBranch() == $this->pushedBranch;
}

/**
* Run an array of given commands
* @param array $commands
*/
protected function runCommands(array $commands){
foreach($commands as $command){

$cmd = $command;
$args = [];

if(is_array($command)){
$cmd = $command[0];
$args = $command[1];
}

Artisan::call($cmd, $args);
}
}

/**
* Perform the deployment task
*
Expand All @@ -208,10 +226,16 @@ public function gitPull(){
escapeshellarg($this->getCurrentBranch()) . ' >> ' .
escapeshellarg($this->config['repo_path'] . '/storage/logs/git-hook.log');

$this->runCommands($this->config['before_pull']);

$pullRequest = shell_exec($cmd);

$this->runCommands($this->config['after_pull']);

return $this->notify([
'cmd' => $cmd,
'user' => shell_exec('whoami'),
'response' => shell_exec($cmd),
'response' => $pullRequest,
]);
}

Expand Down
30 changes: 29 additions & 1 deletion src/config/git-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,35 @@
| It will be transformed into: https://your-domain.tld/another-git-hook
|
*/
'url' => 'git-hook'
'url' => 'git-hook',


/*
|--------------------------------------------------------------------------
| Before pull event
|--------------------------------------------------------------------------
|
| If you have any commands that have to be called before a pull event, specify
| them below.
|
| ['route:clear', ['some:command', ['arg1' => 1]]]
|
*/
'before_pull' => [],


/*
|--------------------------------------------------------------------------
| After pull event
|--------------------------------------------------------------------------
|
| If you have any commands that have to be called after a pull event, specify
| them below.
|
| ['route:clear', ['some:command', ['arg1' => 1]]]
|
*/
'after_pull' => []


];

0 comments on commit 545dbcf

Please sign in to comment.