PHP code example of sevaske / git-webhook-handler

1. Go to this page and download the library: Download sevaske/git-webhook-handler 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/ */

    

sevaske / git-webhook-handler example snippets



jectRootPath = dirname(__DIR__) . DIRECTORY_SEPARATOR;
$requestContent = file_get_contents("php://input");
$gitAlias = 'git';

$webhook = new \GitWebhookHandler\Webhook\Bitbucket(
    $projectRootPath,
    $requestContent,
    $gitAlias
);

$result = $webhook->handlePull(); // boolean


jectRootPath = dirname(__DIR__) . DIRECTORY_SEPARATOR;
$requestContent = file_get_contents("php://input");
$gitAlias = 'git';

$webhook = new \GitWebhookHandler\Webhook\Bitbucket(
    $projectRootPath,
    $requestContent,
    $gitAlias
);

// update and get results of executions
$fetchResult = $webhook->git->fetch();
$pullResult = $webhook->git->pull();

// Execution details
$fetchResult->output; // The result of executing the command "git fetch"
$pullResult->output; // The result of executing the command "git pull origin {your_current_branch}"
$noChanges = \GitWebhookHandler\Terminal\Git::catchNoChanges($pullResult); // True if no changes
$pullErrors = \GitWebhookHandler\Terminal\Git::catchErrors($pullResult); // Array of errors

// Errors & the repo details
$webhook->errors; // Array of errors
$webhook->git->branchName; // Current branch of your project
$webhook->requestHandler->authors; // Array of changes authors (full name, email and nickname)
$webhook->requestHandler->request->repository->full_name; // Repository name

// maybe you want to do something else?
$composerUpdateCommand = "export COMPOSER_HOME=/home/sevaske/.composer && cd {$projectRootPath} && composer update";
$composerUpdateResult = \GitWebhookHandler\Terminal\Command::exec($composerUpdateCommand);
$composerUpdateResult->output; // The result of executing the command "composer update"