From 6b63e47cfd220706e5cc4d60280cc5c03185fb04 Mon Sep 17 00:00:00 2001 From: Sami Tikka Date: Wed, 18 Sep 2013 17:00:55 +0300 Subject: [PATCH] gitcontroller, allows calling webhook for local/remote git project --- PHPCI/Application.php | 2 +- PHPCI/Controller/GitController.php | 60 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 PHPCI/Controller/GitController.php diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 0723c2ad..77bd7170 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -29,7 +29,7 @@ class Application extends b8\Application // Validate the user's session unless it is a login/logout action or a web hook: $sessionAction = ($this->controllerName == 'Session' && in_array($this->action, array('login', 'logout'))); - $externalAction = in_array($this->controllerName, array('Bitbucket', 'Github', 'Gitlab', 'BuildStatus')); + $externalAction = in_array($this->controllerName, array('Bitbucket', 'Github', 'Gitlab', 'BuildStatus', 'Git')); $skipValidation = ($externalAction || $sessionAction); if ($skipValidation || $this->validateSession()) { diff --git a/PHPCI/Controller/GitController.php b/PHPCI/Controller/GitController.php new file mode 100644 index 00000000..a56d057d --- /dev/null +++ b/PHPCI/Controller/GitController.php @@ -0,0 +1,60 @@ + + */ +class GitController extends \PHPCI\Controller +{ + public function init() + { + $this->_buildStore = Store\Factory::getStore('Build'); + } + + /** + * Called by POSTing to /git/webhook/?branch=&commit= + * + * @param string $project + */ + public function webhook($project) + { + $branch = $this->getParam('branch'); + $commit = $this->getParam('commit'); + + try { + $build = new Build(); + $build->setProjectId($project); + + if ($branch !== null && trim($branch) !== '') { + $build->setBranch($branch); + } else { + $build->setBranch('master'); + } + + if ($commit !== null && trim($commit) !== '') { + $build->setCommitId($commit); + } + + $build->setStatus(0); + $build->setLog(''); + $build->setCreated(new \DateTime()); + $this->_buildStore->save($build); + } catch (\Exception $ex) { + die('FAIL'); + } + + die('OK'); + } +}