Merge branch 'feature-gogs'
This commit is contained in:
commit
39196fd454
|
@ -66,6 +66,9 @@ class BuildFactory
|
|||
case 'svn':
|
||||
$type = 'SubversionBuild';
|
||||
break;
|
||||
case 'gogs':
|
||||
$type = 'GogsBuild';
|
||||
break;
|
||||
default:
|
||||
return $build;
|
||||
}
|
||||
|
|
|
@ -276,9 +276,9 @@ class ProjectController extends PHPCensor\Controller
|
|||
$values['key'] = $values['ssh_private_key'];
|
||||
$values['pubkey'] = $values['ssh_public_key'];
|
||||
|
||||
if ($values['type'] == "gitlab") {
|
||||
$accessInfo = $project->getAccessInformation();
|
||||
$reference = $accessInfo["user"].'@'.$accessInfo["domain"].':' . $accessInfo["port"] . '/' . ltrim($project->getReference(), '/') . ".git";
|
||||
if ($values['type'] == 'gitlab') {
|
||||
$accessInfo = $project->getAccessInformation();
|
||||
$reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $accessInfo["port"] . '/' . ltrim($project->getReference(), '/') . ".git";
|
||||
$values['reference'] = $reference;
|
||||
}
|
||||
|
||||
|
@ -332,17 +332,18 @@ class ProjectController extends PHPCensor\Controller
|
|||
|
||||
$options = [
|
||||
'choose' => Lang::get('select_repository_type'),
|
||||
'github' => Lang::get('github'),
|
||||
'bitbucket' => Lang::get('bitbucket'),
|
||||
'gitlab' => Lang::get('gitlab'),
|
||||
'remote' => Lang::get('remote'),
|
||||
'github' => 'GitHub',
|
||||
'bitbucket' => 'Bitbucket',
|
||||
'gitlab' => 'GitLab',
|
||||
'gogs' => 'Gogs',
|
||||
'remote' => 'Git',
|
||||
'local' => Lang::get('local'),
|
||||
'hg' => Lang::get('hg'),
|
||||
'svn' => Lang::get('svn'),
|
||||
'hg' => 'Mercurial (Hg)',
|
||||
'svn' => 'SVN',
|
||||
];
|
||||
|
||||
$field = Form\Element\Select::create('type', Lang::get('where_hosted'), true);
|
||||
$field->setPattern('^(github|bitbucket|gitlab|remote|local|hg|svn)');
|
||||
$field->setPattern('^(github|bitbucket|gitlab|gogs|remote|local|hg|svn)');
|
||||
$field->setOptions($options);
|
||||
$field->setClass('form-control')->setContainerClass('form-group');
|
||||
$form->addField($field);
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014-2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
|
@ -24,16 +16,13 @@ use b8\HttpClient;
|
|||
use b8\Exception\HttpException\NotFoundException;
|
||||
|
||||
/**
|
||||
* Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, etc.
|
||||
* Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, Gogs, etc.
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @author Sami Tikka <stikka@iki.fi>
|
||||
* @author Alex Russell <alex@clevercherry.com>
|
||||
* @author Guillaume Perréal <adirelle@gmail.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Web
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @author Sami Tikka <stikka@iki.fi>
|
||||
* @author Alex Russell <alex@clevercherry.com>
|
||||
* @author Guillaume Perréal <adirelle@gmail.com>
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||
*/
|
||||
class WebhookController extends Controller
|
||||
{
|
||||
|
@ -91,8 +80,8 @@ class WebhookController extends Controller
|
|||
*/
|
||||
public function bitbucket($projectId)
|
||||
{
|
||||
$project = $this->fetchProject($projectId, 'bitbucket');
|
||||
|
||||
$project = $this->fetchProject($projectId, ['bitbucket', 'remote']);
|
||||
|
||||
// Support both old services and new webhooks
|
||||
if ($payload = $this->getParam('payload')) {
|
||||
return $this->bitbucketService(json_decode($payload, true), $project);
|
||||
|
@ -194,7 +183,7 @@ class WebhookController extends Controller
|
|||
*/
|
||||
public function github($projectId)
|
||||
{
|
||||
$project = $this->fetchProject($projectId, 'github');
|
||||
$project = $this->fetchProject($projectId, ['github', 'remote']);
|
||||
|
||||
switch ($_SERVER['CONTENT_TYPE']) {
|
||||
case 'application/json':
|
||||
|
@ -225,9 +214,8 @@ class WebhookController extends Controller
|
|||
*
|
||||
* @param Project $project
|
||||
* @param array $payload
|
||||
* @param b8\Http\Response\JsonResponse $response
|
||||
*
|
||||
* @return b8\Http\Response\JsonResponse
|
||||
* @return array
|
||||
*/
|
||||
protected function githubCommitRequest(Project $project, array $payload)
|
||||
{
|
||||
|
@ -358,7 +346,7 @@ class WebhookController extends Controller
|
|||
*/
|
||||
public function gitlab($projectId)
|
||||
{
|
||||
$project = $this->fetchProject($projectId, 'gitlab');
|
||||
$project = $this->fetchProject($projectId, ['gitlab', 'remote']);
|
||||
|
||||
$payloadString = file_get_contents("php://input");
|
||||
$payload = json_decode($payloadString, true);
|
||||
|
@ -424,6 +412,72 @@ class WebhookController extends Controller
|
|||
return $this->createBuild($project, $commit, $branch, $committer, $commitMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by Gogs Webhooks:
|
||||
*
|
||||
* @param string $projectId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function gogs($projectId)
|
||||
{
|
||||
$project = $this->fetchProject($projectId, ['gogs', 'remote']);
|
||||
switch ($_SERVER['CONTENT_TYPE']) {
|
||||
case 'application/json':
|
||||
$payload = json_decode(file_get_contents('php://input'), true);
|
||||
break;
|
||||
case 'application/x-www-form-urlencoded':
|
||||
$payload = json_decode($this->getParam('payload'), true);
|
||||
break;
|
||||
default:
|
||||
return ['status' => 'failed', 'error' => 'Content type not supported.', 'responseCode' => 401];
|
||||
}
|
||||
|
||||
// Handle Push web hooks:
|
||||
if (array_key_exists('commits', $payload)) {
|
||||
return $this->gogsCommitRequest($project, $payload);
|
||||
}
|
||||
|
||||
return ['status' => 'ignored', 'message' => 'Unusable payload.'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the payload when Gogs sends a commit webhook.
|
||||
*
|
||||
* @param Project $project
|
||||
* @param array $payload
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function gogsCommitRequest(Project $project, array $payload)
|
||||
{
|
||||
if (isset($payload['commits']) && is_array($payload['commits'])) {
|
||||
// If we have a list of commits, then add them all as builds to be tested:
|
||||
$results = [];
|
||||
$status = 'failed';
|
||||
foreach ($payload['commits'] as $commit) {
|
||||
try {
|
||||
$branch = str_replace('refs/heads/', '', $payload['ref']);
|
||||
$committer = $commit['author']['email'];
|
||||
$results[$commit['id']] = $this->createBuild(
|
||||
$project,
|
||||
$commit['id'],
|
||||
$branch,
|
||||
$committer,
|
||||
$commit['message']
|
||||
);
|
||||
$status = 'ok';
|
||||
} catch (Exception $ex) {
|
||||
$results[$commit['id']] = ['status' => 'failed', 'error' => $ex->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
return ['status' => $status, 'commits' => $results];
|
||||
}
|
||||
|
||||
return ['status' => 'ignored', 'message' => 'Unusable payload.'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for creating a new build.
|
||||
*
|
||||
|
|
|
@ -78,7 +78,8 @@ abstract class BaseCommandExecutor implements CommandExecutorInterface
|
|||
$this->lastOutput = [];
|
||||
|
||||
$command = call_user_func_array('sprintf', $args);
|
||||
$this->logger->logDebug($command);
|
||||
$this->logger->logDebug('Command: ' . $command);
|
||||
$this->logger->logDebug('Args: ' . json_encode($args));
|
||||
|
||||
if ($this->quiet) {
|
||||
$this->logger->log('Executing: ' . $command);
|
||||
|
|
|
@ -1,22 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
use PHPCensor\Model\Build;
|
||||
|
||||
/**
|
||||
* BitBucket Build Model
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
* Bitbucket Build Model
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BitbucketBuild extends RemoteGitBuild
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
|
@ -17,11 +10,10 @@ use b8\HttpClient;
|
|||
use PHPCensor\Model\BuildError;
|
||||
|
||||
/**
|
||||
* Github Build Model
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
* Github Build Model
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class GithubBuild extends RemoteGitBuild
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
/**
|
||||
* Gitlab Build Model
|
||||
* @author André Cianfarani <a.cianfarani@c2is.fr>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
* Gitlab Build Model
|
||||
*
|
||||
* @author André Cianfarani <a.cianfarani@c2is.fr>
|
||||
*/
|
||||
class GitlabBuild extends RemoteGitBuild
|
||||
{
|
||||
|
||||
|
|
10
src/PHPCensor/Model/Build/GogsBuild.php
Normal file
10
src/PHPCensor/Model/Build/GogsBuild.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
/**
|
||||
* GogsBuild Build Model
|
||||
*/
|
||||
class GogsBuild extends RemoteGitBuild
|
||||
{
|
||||
}
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
|
@ -13,11 +6,10 @@ use PHPCensor\Model\Build;
|
|||
use PHPCensor\Builder;
|
||||
|
||||
/**
|
||||
* Local Build Model
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
* Local Build Model
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class LocalBuild extends Build
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
|
@ -14,9 +7,8 @@ use PHPCensor\Builder;
|
|||
|
||||
/**
|
||||
* Mercurial Build Model
|
||||
* @author Pavel Gopanenko <pavelgopanenko@gmail.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*
|
||||
* @author Pavel Gopanenko <pavelgopanenko@gmail.com>
|
||||
*/
|
||||
class MercurialBuild extends Build
|
||||
{
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
|
@ -13,11 +6,10 @@ use PHPCensor\Model\Build;
|
|||
use PHPCensor\Builder;
|
||||
|
||||
/**
|
||||
* Remote Git Build Model
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
* Remote Git Build Model
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class RemoteGitBuild extends Build
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCensor\Model\Build;
|
||||
|
||||
|
@ -14,9 +7,8 @@ use PHPCensor\Builder;
|
|||
|
||||
/**
|
||||
* Remote Subversion Build Model
|
||||
* @author Nadir Dzhilkibaev <imam.sharif@gmail.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*
|
||||
* @author Nadir Dzhilkibaev <imam.sharif@gmail.com>
|
||||
*/
|
||||
class SubversionBuild extends Build
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue