Skip to content

Instantly share code, notes, and snippets.

@manaten manaten/hook.php
Last active Dec 19, 2015

Embed
What would you like to do?
PHP webhook program.
<?php
$LOG_FILE = dirname(__FILE__).'/hook.log';
$SECRET_KEY = '** secret **';
if ( isset($_GET['key']) && $_GET['key'] === $SECRET_KEY && isset($_POST['payload']) ) {
$payload = json_decode($_POST['payload'], true);
if ($payload['ref'] === 'refs/heads/master') {
`cd /path/to/repository; git pull origin master`;
file_put_contents($LOG_FILE, date("[Y-m-d H:i:s]")." ".$_SERVER['REMOTE_ADDR']." git pulled: ".$payload['head_commit']['message']."\n", FILE_APPEND|LOCK_EX);
}
} else {
file_put_contents($LOG_FILE, date("[Y-m-d H:i:s]")." invalid access: ".$_SERVER['REMOTE_ADDR']."\n", FILE_APPEND|LOCK_EX);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.