Created
February 2, 2015 12:45
-
-
Save benjibee/856789cfa5e6d7a3aa7f to your computer and use it in GitHub Desktop.
BitBucket Webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* ButBucket Webhook `git pull` automation v0.1 | |
* @author Benji Bilheimer | |
* | |
* If a directory matching the repository name is found | |
* in BASE_PATH, CD into that directory and run a git pull. | |
* | |
*/ | |
define('BASE_PATH', '/htdocs/'); | |
// something like: cd BASE_PATH/name && git pull origin master | |
$command = ''; | |
if ( isset( $_POST['payload'] ) && !empty( $_POST['payload'] ) ) { | |
$data = json_decode( $_POST['payload'], true ); | |
$path = BASE_PATH . $data['repository']['name']; | |
if ( is_readable( $path ) ) { | |
$command = 'cd ' . $path; | |
$command .= ' && git pull origin '; | |
// this should return the current branch | |
$command .= "\"`git branch | grep -E '^\* ' | sed 's/^\* //g'`\""; | |
shell_exec($command); | |
} else { | |
error_log('Webhook Error: path to repo not readable or doesn\'t exist: ' . $path); | |
} | |
} else { | |
error_log('Webhook Error: POST request missing appropriate key or key is empty.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment