From 08af82e84bde9fe4e76ea94e732009103ec099ba Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 25 Feb 2014 09:09:38 +0000 Subject: [PATCH] Updating Gitlab webhook support --- PHPCI/Controller/WebhookController.php | 34 ++++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/PHPCI/Controller/WebhookController.php b/PHPCI/Controller/WebhookController.php index 07cee29d..550036b1 100644 --- a/PHPCI/Controller/WebhookController.php +++ b/PHPCI/Controller/WebhookController.php @@ -175,25 +175,27 @@ class WebhookController extends \PHPCI\Controller */ public function gitlab($project) { - $payload = json_decode(file_get_contents("php://input"), true); + $payload = json_decode($this->getParam('payload'), 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(); + if (isset($payload['commits']) && is_array($payload['commits'])) { + // If we have a list of commits, then add them all as builds to be tested: + + foreach ($payload['commits'] as $commit) { + $build = new Build(); + $build->setProjectId($project); + $build->setCommitId($commit['id']); + $build->setStatus(Build::STATUS_NEW); + $build->setLog(''); + $build->setCreated(new \DateTime()); + $build->setBranch(str_replace('refs/heads/', '', $payload['ref'])); + $build->setCommitterEmail($commit['author']['email']); + $build = $this->buildStore->save($build); + $build->sendStatusPostback(); + } + } + } catch (\Exception $ex) { header('HTTP/1.1 500 Internal Server Error'); header('Ex: ' . $ex->getMessage());