function getRepository($RepoUrl, $Dir) { if (file_exists($Dir)) { echo "Folder " . $Dir . " exists, need git pull.\n"; gitPull($Dir); } else { echo "Folder " . $Dir . "is not there, need git clone.\n"; gitClone($RepoUrl, $Dir); } }
<?php function myExec($command) { $res = ""; $res .= "COMMAND :: {$command} ::\n"; $res .= ":: START OUTPUT ::\n"; $result = array(); exec($command, $result); foreach ($result as $s) { $res .= "{$s}\n"; } $res .= ":: END OUTPUT ::\n\n"; return $res; } function gitPull() { echo myExec("git pull"); echo myExec("git status"); } echo "cron job\n"; gitPull();
throw new \Exception("Missing HTTP 'X-Github-Event' header."); } switch ($_SERVER['CONTENT_TYPE']) { case 'application/json': $json = $rawPost ?: file_get_contents('php://input'); break; case 'application/x-www-form-urlencoded': $json = $_POST['payload']; break; default: throw new \Exception("Unsupported content type: " + $_SERVER['CONTENT_TYPE']); } $payload = json_decode($json); switch (strtolower($_SERVER['HTTP_X_GITHUB_EVENT'])) { case 'push': die(gitPull()); break; default: header('HTTP/1.0 404 Not Found'); echo "Event:{$_SERVER['HTTP_X_GITHUB_EVENT']} Payload:\n"; print_r($payload); die; } function gitPull() { $cmd = 'cd /public_html/ethanzh; git pull git@github.com:ethanzh/NumberGame_JS.git master 2>&1;'; $str = shell_exec($cmd); if (strpos($str, 'error') !== false) { throw new Exception("Shell error: \n" . $str); } return $str;