Skip to content

Instantly share code, notes, and snippets.

@manaten
Last active December 19, 2015 17:19
Show Gist options
  • Save manaten/5990648 to your computer and use it in GitHub Desktop.
Save manaten/5990648 to your computer and use it in GitHub Desktop.
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