, Dan Cryer * @package PHPCI * @subpackage Web */ class GitlabController extends \PHPCI\Controller { /** * @var \PHPCI\Store\BuildStore */ protected $buildStore; public function init() { $this->buildStore = Store\Factory::getStore('Build'); } /** * Called by Gitlab Webhooks: */ public function webhook($project) { $payload = json_decode(file_get_contents("php://input"), true); try { $build = new Build(); $build->setProjectId($project); $build->setCommitId($payload['after']); $build->setStatus(Build::STATUS_NEW); $build->setLog(''); $build->setCreated(new \DateTime()); $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); } catch (\Exception $ex) { header('HTTP/1.1 400 Bad Request'); header('Ex: ' . $ex->getMessage()); die('FAIL'); } try { $build = $this->buildStore->save($build); $build->sendStatusPostback(); } catch (\Exception $ex) { header('HTTP/1.1 500 Internal Server Error'); header('Ex: ' . $ex->getMessage()); die('FAIL'); } die('OK'); } }