Last active
August 29, 2015 14:13
-
-
Save nkgokul/74faed5b3ce34ac57447 to your computer and use it in GitHub Desktop.
Sanity check for Github Webhook
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 | |
//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