Merge pull request #175 from stiggg/git-controller

Git controller, allows calling webhook for local/remote git project
This commit is contained in:
Dan Cryer 2013-10-18 07:15:25 -07:00
commit ed5611c573
2 changed files with 70 additions and 1 deletions

View file

@ -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()) {

View file

@ -0,0 +1,69 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
*/
namespace PHPCI\Controller;
use b8;
use b8\Store;
use PHPCI\Model\Build;
/**
* @author Sami Tikka <stikka@iki.fi>
*/
class GitController extends \PHPCI\Controller
{
public function init()
{
$this->_buildStore = Store\Factory::getStore('Build');
}
/**
* Called by POSTing to /git/webhook/<project_id>?branch=<branch>&commit=<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());
} catch (\Exception $ex) {
header('HTTP/1.1 400 Bad Request');
header('Ex: ' . $ex->getMessage());
die('FAIL');
}
try {
$this->_buildStore->save($build);
} catch (\Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');
header('Ex: ' . $ex->getMessage());
die('FAIL');
}
die('OK');
}
}