Merge a1f5403b32
into 2ddda7711e
This commit is contained in:
commit
43cb4690fa
|
@ -80,11 +80,109 @@ class WebhookController extends \b8\Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by Bitbucket POST service.
|
* Called by Bitbucket.
|
||||||
|
*
|
||||||
|
* @param int $projectId current project id
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function bitbucket($projectId)
|
public function bitbucket($projectId)
|
||||||
{
|
{
|
||||||
$project = $this->fetchProject($projectId, 'bitbucket');
|
$project = $this->fetchProject($projectId, 'bitbucket');
|
||||||
|
|
||||||
|
if ($payload = $this->getParam('payload')) {
|
||||||
|
return $this->bitbucketService(json_decode($payload, true), $project);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case isset($payload['pullrequest_created']):
|
||||||
|
return $this->bitbucketCreatePullRequestWebhook($payload, $project);
|
||||||
|
break;
|
||||||
|
case isset($payload['push']['changes']):
|
||||||
|
return $this->bitbucketPushWebhook($payload, $project);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return array('status' => 'failed', 'commits' => array());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitbucket webhooks for created "pull request".
|
||||||
|
*
|
||||||
|
* @param array $payload incoming request in payload
|
||||||
|
* @param Project $project current project
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function bitbucketCreatePullRequestWebhook($payload, $project)
|
||||||
|
{
|
||||||
|
$results = array();
|
||||||
|
$status = 'failed';
|
||||||
|
try {
|
||||||
|
$results[] = $this->createBuild(
|
||||||
|
$project,
|
||||||
|
$payload['pullrequest_created']['source']['commit']['hash'],
|
||||||
|
$payload['pullrequest_created']['source']['branch']['name'],
|
||||||
|
$payload['pullrequest_created']['author']['username'],
|
||||||
|
$payload['pullrequest_created']['title']
|
||||||
|
);
|
||||||
|
$status = 'ok';
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$results = array('status' => 'failed', 'error' => $ex->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('status' => $status, 'commits' => $results);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitbucket webhooks for "push".
|
||||||
|
*
|
||||||
|
* @param array $payload current request payload
|
||||||
|
* @param Project $project current project
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function bitbucketPushWebhook($payload, $project)
|
||||||
|
{
|
||||||
|
$results = array();
|
||||||
|
$status = 'failed';
|
||||||
|
foreach ($payload['push']['changes'] as $commit) {
|
||||||
|
try {
|
||||||
|
$email = $commit['new']['target']['author']['raw'];
|
||||||
|
$email = substr($email, 0, strpos($email, '>'));
|
||||||
|
$email = substr($email, strpos($email, '<') + 1);
|
||||||
|
|
||||||
|
$results[$commit['new']['target']['hash']] = $this->createBuild(
|
||||||
|
$project,
|
||||||
|
$commit['new']['target']['hash'],
|
||||||
|
$commit['new']['name'],
|
||||||
|
$email,
|
||||||
|
$commit['new']['target']['message']
|
||||||
|
);
|
||||||
|
$status = 'ok';
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$results[$commit['new']['target']['hash']] = array('status' => 'failed', 'error' => $ex->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('status' => $status, 'commits' => $results);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitbucket POST service (old style).
|
||||||
|
*
|
||||||
|
* @param array $payload incoming request in payload
|
||||||
|
* @param Project $project current project
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function bitbucketService($payload, $project)
|
||||||
|
{
|
||||||
$payload = json_decode($this->getParam('payload'), true);
|
$payload = json_decode($this->getParam('payload'), true);
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
78
PHPCI/Plugin/SymfonyCommands.php
Normal file
78
PHPCI/Plugin/SymfonyCommands.php
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHPCI - Continuous Integration for PHP. Plugin for using Symfony2 commands.
|
||||||
|
*
|
||||||
|
* @package PHPCI\Plugin
|
||||||
|
* @author Alexander Gansky <a.gansky@mindteam.com.ua>
|
||||||
|
* @license https://github.com/mindteam/phpci-symfony2-plugin/blob/master/LICENSE
|
||||||
|
* @link http://mindteam.com.ua
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PHPCI\Plugin;
|
||||||
|
|
||||||
|
use PHPCI\Builder;
|
||||||
|
use PHPCI\Model\Build;
|
||||||
|
use Symfony\Component\Yaml\Parser as YamlParser;
|
||||||
|
use PHPCI\Plugin as BaseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin for Symfony2 commands
|
||||||
|
*/
|
||||||
|
class SymfonyCommands implements BaseInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $directory;
|
||||||
|
protected $phpci;
|
||||||
|
protected $build;
|
||||||
|
protected $commandList = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the plugin, configure options, etc.
|
||||||
|
*
|
||||||
|
* @param Builder $phpci
|
||||||
|
* @param Build $build
|
||||||
|
* @param array $options
|
||||||
|
*/
|
||||||
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
||||||
|
{
|
||||||
|
$this->phpci = $phpci;
|
||||||
|
$this->build = $build;
|
||||||
|
$this->directory = $phpci->buildPath;
|
||||||
|
if (isset($options['commands'])) {
|
||||||
|
$this->commandList = $options['commands'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes Symfony2 commands
|
||||||
|
*
|
||||||
|
* @return boolean plugin work status
|
||||||
|
*/
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
$success = true;
|
||||||
|
foreach ($this->commandList as $command) {
|
||||||
|
if (!$this->runSingleCommand($command)) {
|
||||||
|
$success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run one command
|
||||||
|
*
|
||||||
|
* @param string $command command for cymfony
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function runSingleCommand($command)
|
||||||
|
{
|
||||||
|
$cmd = 'php ' . $this->directory . 'app/console ';
|
||||||
|
|
||||||
|
return $this->phpci->executeCommand($cmd . $command, $this->directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,39 +1,34 @@
|
||||||
{
|
{
|
||||||
"name" : "block8/phpci",
|
"name": "block8/phpci",
|
||||||
"description" : "Simple continuous integration for PHP projects.",
|
"description": "Simple continuous integration for PHP projects.",
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"type" : "library",
|
"type": "library",
|
||||||
"keywords" : ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"],
|
"keywords": ["php", "phpci", "ci", "continuous", "integration", "testing", "phpunit", "continuous integration", "jenkins", "travis"],
|
||||||
"homepage" : "http://www.phptesting.org/",
|
"homepage": "http://www.phptesting.org/",
|
||||||
"license" : "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
|
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name" : "Dan Cryer",
|
"name": "Dan Cryer",
|
||||||
"email" : "dan.cryer@block8.co.uk",
|
"email": "dan.cryer@block8.co.uk",
|
||||||
"homepage": "http://www.block8.co.uk",
|
"homepage": "http://www.block8.co.uk",
|
||||||
"role" : "Developer"
|
"role": "Developer"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"support": {
|
"support": {
|
||||||
"email" : "hello+phpci@block8.co.uk",
|
"email": "hello+phpci@block8.co.uk",
|
||||||
"issues": "https://github.com/Block8/PHPCI/issues",
|
"issues": "https://github.com/Block8/PHPCI/issues",
|
||||||
"source": "https://github.com/Block8/PHPCI"
|
"source": "https://github.com/Block8/PHPCI"
|
||||||
},
|
},
|
||||||
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"PHPCI\\": "PHPCI"
|
"PHPCI\\": "PHPCI"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Tests\\PHPCI\\": "Tests/PHPCI/"
|
"Tests\\PHPCI\\": "Tests/PHPCI/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.8",
|
"php": ">=5.3.8",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
|
@ -51,9 +46,9 @@
|
||||||
"pda/pheanstalk": "~3.1",
|
"pda/pheanstalk": "~3.1",
|
||||||
"maknz/slack": "~1.7",
|
"maknz/slack": "~1.7",
|
||||||
"hipchat/hipchat-php": "~1.4",
|
"hipchat/hipchat-php": "~1.4",
|
||||||
"mremi/flowdock": "~1.0"
|
"mremi/flowdock": "~1.0",
|
||||||
|
"mindteam/phpci-symfony2-plugin": "dev-master"
|
||||||
},
|
},
|
||||||
|
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~4.5",
|
"phpunit/phpunit": "~4.5",
|
||||||
"phpmd/phpmd": "~2.0",
|
"phpmd/phpmd": "~2.0",
|
||||||
|
@ -62,7 +57,7 @@
|
||||||
"phploc/phploc": "~2.0",
|
"phploc/phploc": "~2.0",
|
||||||
"jakub-onderka/php-parallel-lint": "0.8.*"
|
"jakub-onderka/php-parallel-lint": "0.8.*"
|
||||||
},
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"block8/php-docblock-checker": "PHP Docblock Checker",
|
"block8/php-docblock-checker": "PHP Docblock Checker",
|
||||||
"phpmd/phpmd": "PHP Mess Detector",
|
"phpmd/phpmd": "PHP Mess Detector",
|
||||||
|
|
492
composer.lock
generated
492
composer.lock
generated
File diff suppressed because it is too large
Load diff
42
local_vars.php
Normal file
42
local_vars.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Define our APPLICATION_PATH, if not already defined:
|
||||||
|
if (!defined('APPLICATION_PATH')) {
|
||||||
|
define('APPLICATION_PATH', dirname(__FILE__) . '/');
|
||||||
|
define('PHPCI_DIR', APPLICATION_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define our PHPCI_URL, if not already defined:
|
||||||
|
if (!defined('PHPCI_URL') && isset($config)) {
|
||||||
|
define('PHPCI_URL', $config->get('phpci.url', '') . '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define PHPCI_BIN_DIR
|
||||||
|
if (!defined('PHPCI_BIN_DIR')) {
|
||||||
|
define('PHPCI_BIN_DIR', PHPCI_DIR . 'vendor/bin/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define PHPCI_BUILD_ROOT_DIR
|
||||||
|
if (!defined('PHPCI_BUILD_ROOT_DIR')) {
|
||||||
|
define('PHPCI_BUILD_ROOT_DIR', PHPCI_DIR . 'PHPCI/build/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should PHPCI run the Shell plugin?
|
||||||
|
if (!defined('ENABLE_SHELL_PLUGIN')) {
|
||||||
|
define('ENABLE_SHELL_PLUGIN', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this is not already defined, we're not running in the console:
|
||||||
|
if (!defined('PHPCI_IS_CONSOLE')) {
|
||||||
|
define('PHPCI_IS_CONSOLE', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!defined('IS_WIN')) {
|
||||||
|
define('IS_WIN', ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If an environment variable is set defining our config location, use that
|
||||||
|
// otherwise fall back to PHPCI/config.yml.
|
||||||
|
if (!defined('PHPCI_CONFIG_FILE')) {
|
||||||
|
define('PHPCI_CONFIG_FILE', $configFile);
|
||||||
|
}
|
Loading…
Reference in a new issue