Last active
December 19, 2015 17:19
-
-
Save manaten/5990648 to your computer and use it in GitHub Desktop.
PHP webhook program.
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 | |
$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