Skip to content

Instantly share code, notes, and snippets.

@nkgokul
Last active August 29, 2015 14:13
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 nkgokul/74faed5b3ce34ac57447 to your computer and use it in GitHub Desktop.
Save nkgokul/74faed5b3ce34ac57447 to your computer and use it in GitHub Desktop.
Sanity check for Github Webhook
<?php
//Github sanity check
$secret = 'my_secret_entered_on_webhook_settings_page';
$headers = getallheaders();
$hubSignature = $headers['X-Hub-Signature'];
list($algo, $hash) = explode('=', $hubSignature, 2);
$payload = file_get_contents('php://input');
$data = json_decode($payload);
$payloadHash = hash_hmac($algo, $payload, $secret);
if ($hash !== $payloadHash) {
die('Bad secret');
}
/** If its a release hook then you will have release.
if (isset($data->release)) {
echo $data->release->tag_name;
echo $data->release->zipball_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment