Skip to content

Instantly share code, notes, and snippets.

@cobbdb
Created February 18, 2017 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cobbdb/452cf2cbebf49db9744806e503262683 to your computer and use it in GitHub Desktop.
Save cobbdb/452cf2cbebf49db9744806e503262683 to your computer and use it in GitHub Desktop.
Github webhook quick example
<?php
function writeLog($msg) {
$fout = fopen('log.txt', 'w');
fwrite($fout, $msg);
fclose($fout);
}
$headers = getallheaders();
if (array_key_exists('X-Github-Event', $headers)) {
if ($headers['X-Github-Event'] === 'push') {
$body = file_get_contents('php://input');
$data = json_decode($body);
if ($data->ref === 'refs/heads/master') {
writeLog("Something happened to master!\n\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment