Merge branch 'master' of github.com:Block8/PHPCI

This commit is contained in:
Dan Cryer 2013-07-30 02:56:10 +01:00
commit c935c5c7ee
3 changed files with 86 additions and 3 deletions

View file

@ -28,7 +28,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', 'BuildStatus'));
$externalAction = in_array($this->controllerName, array('Bitbucket', 'Github', 'Gitlab', 'BuildStatus'));
$skipValidation = ($externalAction || $sessionAction);
if($skipValidation || $this->validateSession()) {

View file

@ -0,0 +1,61 @@
<?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;
/**
* Gitlab Controller - Processes webhook pings from Gitlab.
* @author Alex Russell <alex@clevercherry.com>, Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Web
*/
class GitlabController extends \PHPCI\Controller
{
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(0);
$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');
}
}

View file

@ -26,6 +26,8 @@ class PhpCodeSniffer implements \PHPCI\Plugin
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath;
$this->standard = isset($options['standard']) ? $options['standard'] : 'PSR2';
$this->tab_width = isset($options['tab_width']) ? $options['tab_width'] : '';
$this->encoding = isset($options['encoding']) ? $options['encoding'] : '';
}
/**
@ -39,7 +41,27 @@ class PhpCodeSniffer implements \PHPCI\Plugin
$ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
}
$cmd = PHPCI_BIN_DIR . 'phpcs --standard=%s %s "%s"';
return $this->phpci->executeCommand($cmd, $this->standard, $ignore, $this->phpci->buildPath);
$standard = '';
if (strpos($this->standard, '/') !== false) {
$standard = ' --standard='.$this->directory.$this->standard;
} else {
$standard = ' --standard='.$this->standard;
}
$tab_width = '';
if (strlen($this->tab_width)) {
$tab_width = ' --tab-width='.$this->tab_width;
}
$encoding = '';
if (strlen($this->encoding)) {
$encoding = ' --encoding='.$this->encoding;
}
$cmd = PHPCI_BIN_DIR . 'phpcs %s %s %s %s "%s"';
return $this->phpci->executeCommand($cmd, $standard, $ignore, $tab_width, $encoding, $this->phpci->buildPath);
}
}