Last active
November 11, 2019 16:06
-
-
Save jellehak/5be83e24eae383bb9cae974ca620ef49 to your computer and use it in GitHub Desktop.
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 | |
// Script to handle github webhook | |
// https://developer.github.com/webhooks/ | |
// ========================= | |
// CONFIG | |
// ========================= | |
// Set in Github | |
$secret = ""; // (optional but recommended) this makes this endpoint only availible to github e.g. veryverysecret | |
$remote = "[email protected]:yourorg/reponame.git"; | |
$branch = "master"; | |
$path = ".."; | |
// ========================= | |
// Code | |
// ========================= | |
// Check secret | |
if (isset($secret)) { | |
// https://developer.github.com/webhooks/securing/ | |
$body = file_get_contents('php://input'); | |
$signature = str_replace("sha1=","", $_SERVER['HTTP_X_HUB_SIGNATURE']); | |
$hash = hash_hmac('sha1', $body, $secret); | |
if ($signature != $hash) { | |
exit ("Not for you"); | |
} | |
} | |
if($_GET['action'] == 'pull') { | |
echo "Fetching...\n"; | |
function execPrint($command) { | |
$result = array(); | |
exec($command, $output, $result); | |
print_r($output); | |
} | |
$cmd = "cd $path && git pull $remote $branch"; | |
echo "Running: $cmd\n"; | |
echo "\n"; | |
// Print the exec output inside of a pre element | |
print(execPrint($cmd)); | |
} else { | |
exit("Nothing"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment