pusher->email . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; } // check if the request comes from github server $github_ips = array('207.97.227.253', '50.57.128.197', '108.171.174.178', '50.57.231.61'); if (in_array($_SERVER['REMOTE_ADDR'], $github_ips)) { foreach ($config['endpoints'] as $endpoint) { // check if the push came from the right repository and branch if ($payload->repository->url == 'https://github.com/' . $endpoint['repo'] && $payload->ref == 'refs/heads/' . $endpoint['branch']) { // execute update script, and record its output ob_start(); passthru($endpoint['run']); $output = ob_end_contents(); // prepare and send the notification email if (isset($config['email'])) { // send mail to someone, and the github user who pushed the commit $body = '
The Github user @' . $payload->pusher->name . '' . ' has pushed to ' . $payload->repository->url . ' and consequently, ' . $endpoint['action'] . '.
'; $body .= 'Here\'s a brief list of what has been changed:
'; $body .= 'What follows is the output of the script:
';
$body .= $output. '';
$body .= 'Cheers,
Github Webhook Endpoint