Skip to content

Instantly share code, notes, and snippets.

@tobalsan
Created July 29, 2014 11:32
Show Gist options
  • Save tobalsan/4767985370b6cb0ded3c to your computer and use it in GitHub Desktop.
Save tobalsan/4767985370b6cb0ded3c to your computer and use it in GitHub Desktop.
<?php
header("Content-type: text/plain");
$json = file_get_contents('php://input');
$data = json_decode($json,true);
$file = __DIR__ . '/../app/logs/git.log';
$date = date('Y-m-d H:i:s');
if(!count($data['commits'])) {
file_put_contents($file,"\n" . $date . " : Failed attempt to trigger git web hook (by ip " . $_SERVER['REMOTE_ADDR'] . ")", FILE_APPEND);
exit('Direct access to this resource is not allowed.');
} else {
`cd .. | git pull`;
file_put_contents($file,"\n" . $date . " : Successful update by git web hook (by ip " . $_SERVER['REMOTE_ADDR'] . ")", FILE_APPEND);
exit('Hook successfully triggered');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment