Last active
April 14, 2016 06:26
-
-
Save seayxu/bf7a9e4a6b4db74088daaaa3f990843b to your computer and use it in GitHub Desktop.
git webhook sample for php
This file contains hidden or 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 | |
/* | |
* 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