Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Irfan-Ansari/9505378 to your computer and use it in GitHub Desktop.
Save Irfan-Ansari/9505378 to your computer and use it in GitHub Desktop.
<?php
// Edit these to match your environment settings
define( 'BASE_PATH', '/home/username/webapps' );
// This is the path to the git executable
define( 'GIT_PATH', get_full_path( '/git/bin/git' ) );
// Edit this array so the key matches the github repo name and the value is path of the repo relative to the BASE_PATH
$repository_paths = array(
'test' => '/git-test'
);
if( isset( $_POST['payload'] ) ) {
$payload = json_decode( stripslashes( $_POST['payload'] ) );
if( isset( $repository_paths[ $payload->repository->name ] ) ) {
$path = get_full_path( $repository_paths[ $payload->repository->name ] );
$cmd = sprintf( 'cd %s; ', $path );
$cmd .= sprintf( '%s pull', GIT_PATH );
shell_exec( $cmd );
die( "Executed: $cmd!" );
}
}
die( 'Dont\'t think you\'re sposed to be here...' );
function get_full_path( $path ) {
return BASE_PATH . $path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment