phpci/PHPCI/Controller/BitbucketController.php

52 lines
944 B
PHP
Raw Normal View History

2013-05-10 13:28:43 +02:00
<?php
namespace PHPCI\Controller;
use b8,
b8\Store,
PHPCI\Model\Build;
class BitbucketController extends b8\Controller
{
public function init()
{
$this->_buildStore = Store\Factory::getStore('Build');
}
public function webhook($project)
{
2013-05-10 18:15:48 +02:00
$payload = json_decode($this->getParam('payload'), true);
2013-05-10 17:25:37 +02:00
$branches = array();
$commits = array();
2013-05-10 13:28:43 +02:00
2013-05-10 17:25:37 +02:00
foreach($payload['commits'] as $commit)
2013-05-10 13:28:43 +02:00
{
2013-05-10 17:25:37 +02:00
if(!in_array($commit['branch'], $branches))
{
$branches[] = $commit['branch'];
$commits[$commit['branch']] = $commit['raw_node'];
}
2013-05-10 13:28:43 +02:00
}
2013-05-10 17:25:37 +02:00
foreach($branches as $branch)
2013-05-10 13:28:43 +02:00
{
2013-05-10 17:25:37 +02:00
try
{
$build = new Build();
$build->setProjectId($project);
$build->setCommitId($commits[$branch]);
$build->setStatus(0);
$build->setLog('');
$build->setCreated(new \DateTime());
$build->setBranch($branch);
$this->_buildStore->save($build);
}
catch(\Exception $ex)
{
}
2013-05-10 13:28:43 +02:00
}
die('OK');
}
}