diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 60fb44db..283e419c 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -149,6 +149,7 @@ class Builder mkdir($this->buildPath, 0777, true); file_put_contents($keyFile, $key); + chmod($keyFile, 0600); $this->executeCommand('ssh-agent ssh-add '.$keyFile.' && git clone -b ' .$this->build->getBranch() . ' ' .$url.' '.$this->buildPath.' && ssh-agent -k'); unlink($keyFile); diff --git a/PHPCI/Controller/GithubController.php b/PHPCI/Controller/GithubController.php index 9e292084..516bcf4f 100644 --- a/PHPCI/Controller/GithubController.php +++ b/PHPCI/Controller/GithubController.php @@ -13,18 +13,37 @@ class GithubController extends b8\Controller $this->_buildStore = Store\Factory::getStore('Build'); } - public function index() + public function webhook($project) { - $payload = json_decode($this->getParam('payload')); + $payload = json_decode($this->getParam('payload'), true); - $build = new Build(); - $build->setProjectId($this->getParam('project')); - $build->setCommitId($payload['after']); - $build->setStatus(0); - $build->setLog(''); - $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); + try + { + $build = new Build(); + $build->setProjectId($project); + $build->setCommitId($payload['after']); + $build->setStatus(0); + $build->setLog(''); + $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); + } + catch(\Exception $ex) + { + header('HTTP/1.1 400 Bad Request'); + header('Ex: ' . $ex->getMessage()); + die('FAIL'); + } - $this->_buildStore->save($build); + try + { + $this->_buildStore->save($build); + } + catch(\Exception $ex) + { + header('HTTP/1.1 500 Internal Server Error'); + header('Ex: ' . $ex->getMessage()); + die('FAIL'); + } + die('OK'); } } \ No newline at end of file