Skip to content

Instantly share code, notes, and snippets.

@seayxu
Last active April 14, 2016 06:26
Show Gist options
  • Save seayxu/bf7a9e4a6b4db74088daaaa3f990843b to your computer and use it in GitHub Desktop.
Save seayxu/bf7a9e4a6b4db74088daaaa3f990843b to your computer and use it in GitHub Desktop.
git webhook sample for php
<?php
/*
* description: git webhook sample
* author: seayxu
* email: [email protected]
*/
header('Content-type: text/html;charset=utf-8');
ini_set('date.timezone','Asia/Shanghai');
error_reporting(1);
$token = '';
$branch = '';
$json = json_decode(file_get_contents('php://input'), true);
if (empty($json['token']) || $json['token'] !== $token) {
exit('error request');
}
write($json);
$ref = $json['ref'];
if (empty($ref)) {
die("error request");
}
if ($ref==$branch) {
$cmd = "./deploy.sh";
shell_exec($cmd);
echo $json;
}
else{
echo "branch is not right";
}
//write text into file
public function write($context='')
{
$fileName = date('YmdHis')+'.json';
$file = fopen($fileName, "w");
fwrite($file, $context);
fclose($file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment