Skip to content

Instantly share code, notes, and snippets.

@patrick-hertling
Created September 29, 2015 13:49
Show Gist options
  • Save patrick-hertling/942962a354d295d7bdd2 to your computer and use it in GitHub Desktop.
Save patrick-hertling/942962a354d295d7bdd2 to your computer and use it in GitHub Desktop.
GIT Webhook
<?php
/**
* GIT Webhook
*
* Instructions:
* 1. Set up SSH Keys
* 2. Register SSH Keys and Webhook on VCS
* 3. Set up the GIT remote vía SSH
* 4. Register variables in this script
*
* On every push matching the variables, the changes get pulled in
*
******************************************************************************/
$remote = 'origin';
$branch_listen = 'dev-master';
$repo_listen = 39454301;
/*******************************************************************************/
$payload = file_get_contents('php://input');
$data = json_decode($payload);
list($first, $second, $branch) = explode("/", $data->ref);
$repo = $data->repository->id;
// If something gets pushed to the listening branch, pull changes in
$listening_action = (($branch_listen == $branch) && ($repo_listen === $repo));
if ($listening_action) {
$result = shell_exec('git pull '.$remote.' '.$branch);
// TODO: Handle errors if the pull fails.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment