PHP code example of szykra / gitlab-hook-receiver
1. Go to this page and download the library: Download szykra/gitlab-hook-receiver library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
szykra / gitlab-hook-receiver example snippets
$directory = '/path/to/your/project/directory';
// Instance of Logger, in this case it's Monolog
$logger = new Logger("ON_PUSH", [new StreamHandler('hook.log')]);
// Create new Receiver and inject instance of Logger
$receiver = new GitLabRequestReceiver($logger);
// Set Gitlab POST data to Receiver Object
$receiver->prepareData(file_get_contents('php://input'));
// Add GitPullCommandListener to Receiver, argument is your git repository
// It automatically pull changes from current project branch
$receiver->addCommandListener(new GitPullCommandListener($directory));
// Add ComposerCommandListener to Receiver, argument is your project directory with composer.json file
// Now you can transfer composer action through commit message e.g. [composer:update]
$receiver->addCommandListener(new ComposerCommandListener($directory));
// Run all listeners
$receiver->run();