Compare commits

...

6 commits
master ... gogs

Author SHA1 Message Date
Simon Vieille dc34f49819 build image in README 2016-12-05 09:27:44 +01:00
Simon Vieille 7ca6f7a78c phpci 2016-12-05 09:15:02 +01:00
Simon Vieille adbf294b0b Gogs integration 2016-12-05 01:19:45 +01:00
Simon Vieille 222c397b0b Gogs integration 2016-12-05 01:09:16 +01:00
Simon Vieille f98900898e Gogs integration 2016-12-05 01:02:32 +01:00
Simon Vieille 32054ee565 Gogs integration 2016-12-05 00:58:11 +01:00
17 changed files with 156 additions and 36 deletions

View file

@ -35,4 +35,3 @@ test:
broken:
email:
committer: true
cc: ["php-ci@googlegroups.com"]

View file

@ -48,6 +48,9 @@ class BuildFactory
case 'remote':
$type = 'RemoteGitBuild';
break;
case 'gogs':
$type = 'RemoteGitBuild';
break;
case 'local':
$type = 'LocalBuild';
break;

View file

@ -315,6 +315,7 @@ class ProjectController extends PHPCI\Controller
'github' => Lang::get('github'),
'bitbucket' => Lang::get('bitbucket'),
'gitlab' => Lang::get('gitlab'),
'gogs' => Lang::get('gogs'),
'remote' => Lang::get('remote'),
'local' => Lang::get('local'),
'hg' => Lang::get('hg'),
@ -322,7 +323,7 @@ class ProjectController extends PHPCI\Controller
);
$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);
@ -425,6 +426,10 @@ class ProjectController extends PHPCI\Controller
'regex' => '/^(git|https?):\/\//',
'message' => Lang::get('error_remote')
),
'gogs' => array(
'regex' => '/^(git|https?):\/\//',
'message' => Lang::get('error_remote')
),
'gitlab' => array(
'regex' => '`^(.*)@(.*):(.*)/(.*)\.git`',
'message' => Lang::get('error_gitlab')

View file

@ -1,32 +1,29 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
* PHPCI - Continuous Integration for PHP.
*
* @copyright Copyright 2014-2015, Block 8 Limited.
* @copyright Copyright 2014-2015, Block 8 Limited
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
*
* @link https://www.phptesting.org/
*/
namespace PHPCI\Controller;
use b8;
use b8\Store;
use Exception;
use PHPCI\BuildFactory;
use PHPCI\Model\Project;
use PHPCI\Service\BuildService;
use PHPCI\Store\BuildStore;
use PHPCI\Store\ProjectStore;
/**
* 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
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
@ -58,9 +55,8 @@ class WebhookController extends \b8\Controller
}
/** Handle the action, Ensuring to return a JsonResponse.
*
* @param string $action
* @param mixed $actionParams
* @param mixed $actionParams
*
* @return \b8\Http\Response
*/
@ -78,6 +74,7 @@ class WebhookController extends \b8\Controller
$response->setResponseCode(500);
$response->setContent(array('status' => 'failed', 'error' => $ex->getMessage()));
}
return $response;
}
@ -87,19 +84,19 @@ class WebhookController extends \b8\Controller
public function bitbucket($projectId)
{
$project = $this->fetchProject($projectId, 'bitbucket');
// Support both old services and new webhooks
if ($payload = $this->getParam('payload')) {
return $this->bitbucketService(json_decode($payload, true), $project);
}
$payload = json_decode(file_get_contents("php://input"), true);
$payload = json_decode(file_get_contents('php://input'), true);
if (empty($payload['push']['changes'])) {
// Invalid event from bitbucket
return [
'status' => 'failed',
'commits' => []
'commits' => [],
];
}
@ -167,7 +164,7 @@ class WebhookController extends \b8\Controller
}
/**
* Called by POSTing to /webhook/git/<project_id>?branch=<branch>&commit=<commit>
* Called by POSTing to /webhook/git/<project_id>?branch=<branch>&commit=<commit>.
*
* @param string $projectId
*/
@ -183,7 +180,7 @@ class WebhookController extends \b8\Controller
}
/**
* Called by Github Webhooks:
* Called by Github Webhooks:.
*/
public function github($projectId)
{
@ -216,8 +213,8 @@ class WebhookController extends \b8\Controller
/**
* Handle the payload when Github sends a commit webhook.
*
* @param Project $project
* @param array $payload
* @param Project $project
* @param array $payload
* @param b8\Http\Response\JsonResponse $response
*
* @return b8\Http\Response\JsonResponse
@ -256,6 +253,7 @@ class WebhookController extends \b8\Controller
$results[$commit['id']] = array('status' => 'failed', 'error' => $ex->getMessage());
}
}
return array('status' => $status, 'commits' => $results);
}
@ -264,6 +262,7 @@ class WebhookController extends \b8\Controller
$branch = str_replace('refs/tags/', 'Tag: ', $payload['ref']);
$committer = $payload['pusher']['email'];
$message = $payload['head_commit']['message'];
return $this->createBuild($project, $payload['after'], $branch, $committer, $message);
}
@ -274,7 +273,7 @@ class WebhookController extends \b8\Controller
* Handle the payload when Github sends a Pull Request webhook.
*
* @param Project $project
* @param array $payload
* @param array $payload
*/
protected function githubPullRequest(Project $project, array $payload)
{
@ -287,11 +286,11 @@ class WebhookController extends \b8\Controller
$token = \b8\Config::getInstance()->get('phpci.github.token');
if (!empty($token)) {
$headers[] = 'Authorization: token ' . $token;
$headers[] = 'Authorization: token '.$token;
}
$url = $payload['pull_request']['commits_url'];
$http = new \b8\HttpClient();
$url = $payload['pull_request']['commits_url'];
$http = new \b8\HttpClient();
$http->setHeaders($headers);
$response = $http->get($url);
@ -336,13 +335,13 @@ class WebhookController extends \b8\Controller
}
/**
* Called by Gitlab Webhooks:
* Called by Gitlab Webhooks:.
*/
public function gitlab($projectId)
{
$project = $this->fetchProject($projectId, 'gitlab');
$payloadString = file_get_contents("php://input");
$payloadString = file_get_contents('php://input');
$payload = json_decode($payloadString, true);
// build on merge request events
@ -379,6 +378,71 @@ class WebhookController extends \b8\Controller
$results[$commit['id']] = array('status' => 'failed', 'error' => $ex->getMessage());
}
}
return array('status' => $status, 'commits' => $results);
}
return array('status' => 'ignored', 'message' => 'Unusable payload.');
}
/**
* Called by Gogs Webhooks:.
*/
public function gogs($projectId)
{
$project = $this->fetchProject($projectId, 'gogs');
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 array('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 array('status' => 'ignored', 'message' => 'Unusable payload.');
}
/**
* Handle the payload when Gogs sends a commit webhook.
*
* @param Project $project
* @param array $payload
* @param b8\Http\Response\JsonResponse $response
*
* @return b8\Http\Response\JsonResponse
*/
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 = array();
$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']] = array('status' => 'failed', 'error' => $ex->getMessage());
}
}
return array('status' => $status, 'commits' => $results);
}
@ -389,11 +453,11 @@ class WebhookController extends \b8\Controller
* Wrapper for creating a new build.
*
* @param Project $project
* @param string $commitId
* @param string $branch
* @param string $committer
* @param string $commitMessage
* @param array $extra
* @param string $commitId
* @param string $branch
* @param string $committer
* @param string $commitMessage
* @param array $extra
*
* @return array
*
@ -413,7 +477,7 @@ class WebhookController extends \b8\Controller
if ($builds['count']) {
return array(
'status' => 'ignored',
'message' => sprintf('Duplicate of build #%d', $builds['items'][0]->getId())
'message' => sprintf('Duplicate of build #%d', $builds['items'][0]->getId()),
);
}
@ -426,26 +490,26 @@ class WebhookController extends \b8\Controller
/**
* Fetch a project and check its type.
*
* @param int $projectId
* @param int $projectId
* @param array|string $expectedType
*
* @return Project
*
* @throws Exception If the project does not exist or is not of the expected type.
* @throws Exception If the project does not exist or is not of the expected type
*/
protected function fetchProject($projectId, $expectedType)
{
$project = $this->projectStore->getById($projectId);
if (empty($projectId)) {
throw new Exception('Project does not exist: ' . $projectId);
throw new Exception('Project does not exist: '.$projectId);
}
if (is_array($expectedType)
? !in_array($project->getType(), $expectedType)
: $project->getType() !== $expectedType
) {
throw new Exception('Wrong project type: ' . $project->getType());
throw new Exception('Wrong project type: '.$project->getType());
}
return $project;

View file

@ -98,6 +98,7 @@ i din foretrukne hosting-platform.',
'github' => 'GitHub',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'gogs' => 'Gogs',
'remote' => 'Ekstern URL',
'local' => 'Lokalt filsystem',
'hg' => 'Mercurial',
@ -146,6 +147,9 @@ and Services</a> under dit GitHub-repository.',
'webhooks_help_gitlab' => 'For at køre dette build automatisk når nye commits bliver pushed kan du tilføje nedenstående URL
som en "WebHook URL" i Web Hooks-sektionen i dit GitLab-repository.',
'webhooks_help_gitlab' => 'For at køre dette build automatisk når nye commits bliver pushed kan du tilføje nedenstående URL
som en "WebHook URL" i Web Hooks-sektionen i dit Gogs-repository.',
'webhooks_help_bitbucket' => 'For at køre dette build automatisk når nye commits bliver pushed skal du tilføje nedenstående
URL som "POST" service i
<a href="https://bitbucket.org/%s/admin/services">

View file

@ -99,6 +99,7 @@ generiert. Um es zu verwenden, fügen Sie einfach den folgenden Public Key im Ab
'github' => 'GitHub',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'gogs' => 'Gogs',
'remote' => 'Externe URL',
'local' => 'Lokaler Pfad',
'hg' => 'Mercurial',
@ -148,6 +149,8 @@ generiert. Um es zu verwenden, fügen Sie einfach den folgenden Public Key im Ab
'webhooks_help_gitlab' => 'Um für dieses Projekt automatisch einen Build zu starten, wenn neue Commits gepushed werden, fügen Sie die untenstehende URL in der Web Hooks Sektion Ihres GitLab Repositories hinzu.',
'webhooks_help_gogs' => 'Um für dieses Projekt automatisch einen Build zu starten, wenn neue Commits gepushed werden, fügen Sie die untenstehende URL in der Web Hooks Sektion Ihres Gogs Repositories hinzu.',
'webhooks_help_bitbucket' => 'Um für dieses Projekt automatisch einen Build zu starten, wenn neue Commits gepushed werden, fügen Sie die untenstehende URL als "POST" Service in der <a href="https://bitbucket.org/%s/admin/services">Services</a>-Sektion Ihres Bitbucket Repositories hinzu.',
// View Build

View file

@ -99,6 +99,7 @@ PHPCI',
'github' => 'GitHub',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'gogs' => 'Gogs',
'remote' => 'Απομακρυσμένη διεύθυνση URL',
'local' => 'Τοπική Διαδρομή',
'hg' => 'Ευμετάβλητο',
@ -147,6 +148,9 @@ and Services</a> του GitHub αποθετηρίου σας.',
'webhooks_help_gitlab' => 'Για την αυτόματη κατασκευή αυτού του έργου όταν υπάρχουν νέες συνεισφορές, προσθέστε την διεύθυνση URL παρακάτω
σαν "WebHook URL" στο τμήμα Web Hooks του GitLab αποθετηρίου σας.',
'webhooks_help_gogs' => 'Για την αυτόματη κατασκευή αυτού του έργου όταν υπάρχουν νέες συνεισφορές, προσθέστε την διεύθυνση URL παρακάτω
σαν "WebHook URL" στο τμήμα Web Hooks του Gogs αποθετηρίου σας.',
'webhooks_help_bitbucket' => 'Για την αυτόματη κατασκευή αυτού του έργου όταν υπάρχουν νέες συνεισφορές, προσθέστε τη διεύθυνση URL παρακάτω
ως μια υπηρεσία "POST" στο τμήμα <a href="https://bitbucket.org/%s/admin/services">
Services</a> του Bitbucket αποθετηρίου σας.',

View file

@ -99,6 +99,7 @@ PHPCI',
'github' => 'GitHub',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'gogs' => 'Gogs',
'remote' => 'Remote URL',
'local' => 'Local Path',
'hg' => 'Mercurial',
@ -148,6 +149,9 @@ PHPCI',
'webhooks_help_gitlab' => 'To automatically build this project when new commits are pushed, add the URL below
as a "WebHook URL" in the Web Hooks section of your GitLab repository.',
'webhooks_help_gogs' => 'To automatically build this project when new commits are pushed, add the URL below
as a "WebHook URL" in the Web Hooks section of your Gogs repository.',
'webhooks_help_bitbucket' => 'To automatically build this project when new commits are pushed, add the URL below
as a "POST" service in the
<a href="https://bitbucket.org/%s/admin/services">

View file

@ -99,6 +99,7 @@ PHPCI',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'remote' => 'URL Remota',
'gogs' => 'Gogs',
'local' => 'Path local',
'hg' => 'Mercurial',
'svn' => 'Subversion',
@ -146,6 +147,9 @@ PHPCI',
'webhooks_help_gitlab' => 'Para compilar automáticamente este proyecto, cada vez que se realiza un commit, agreagar la siguiente URL
como una "WebHook URL" en la sección "web hooks" de tu repositorio en GitLab.',
'webhooks_help_gogs' => 'Para compilar automáticamente este proyecto, cada vez que se realiza un commit, agreagar la siguiente URL
como una "WebHook URL" en la sección "web hooks" de tu repositorio en Gogs.',
'webhooks_help_bitbucket' => 'Para compilar automáticamente este proyecto, cada vez que se realiza un commit, agreagar la siguiente URL
como un servicio "POST" en la sección
<a href="https://bitbucket.org/%s/admin/services">

View file

@ -99,6 +99,7 @@ PHPCI',
'github' => 'GitHub',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'gogs' => 'Gogs',
'remote' => 'URL distante',
'local' => 'Chemin local',
'hg' => 'Mercurial',
@ -147,6 +148,9 @@ PHPCI',
'webhooks_help_gitlab' => 'Pour générer un build quand de nouveaux commits sont poussés, ajouter l\'url suivante
and tant que "WebHook URL" dans la section Web Hooks de votre dépôt GitLab.',
'webhooks_help_gogs' => 'Pour générer un build quand de nouveaux commits sont poussés, ajouter l\'url suivante
and tant que "WebHook URL" dans la section Web Hooks de votre dépôt Gogs.',
'webhooks_help_bitbucket' => 'Pour générer un build quand de nouveaux commits sont poussés, ajouter l\'url suivante
en tant que service "POST" dans la section
<a href="https://bitbucket.org/%s/admin/services">

View file

@ -99,6 +99,7 @@ PHPCI',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'remote' => 'URL Remoto',
'gogs' => 'Gogs',
'local' => 'Percorso Locale',
'hg' => 'Mercurial',
@ -149,6 +150,10 @@ PHPCI',
aggiungi l\'URL seguente come "Webhook URL" nella sezione "WebHook URL" del tuo
repository GitLab.',
'webhooks_help_gogs' => 'Per effettuare la build automatica di questo progetto quando vengono inseriti nuovi commit,
aggiungi l\'URL seguente come "Webhook URL" nella sezione "WebHook URL" del tuo
repository Gogs.',
'webhooks_help_bitbucket' => 'Per effettuare la build automatica di questo progetto quando vengono inseriti nuovi
commit, aggiungi l\'URL seguente come serizio "POST" nella sezione
<a href="https://bitbucket.org/%s/admin/services">Services</a> del tuo repository su

View file

@ -99,6 +99,7 @@ van je gekozen source code hosting platform',
'github' => 'GitHub',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'gogs' => 'Gogs',
'remote' => 'Externe URL',
'local' => 'Lokaal pad',
'hg' => 'Mercurial',
@ -147,6 +148,9 @@ and Services</a> sectie van je GitHub repository toegevoegd worden.',
'webhooks_help_gitlab' => 'Voor automatische builds wanneer nieuwe commits worden gepusht, dient onderstaande URL
als nieuwe "Webhook URL" in de Web Hooks sectie van je GitLab repository toegevoegd worden.',
'webhooks_help_gogs' => 'Voor automatische builds wanneer nieuwe commits worden gepusht, dient onderstaande URL
als nieuwe "Webhook URL" in de Web Hooks sectie van je Gogs repository toegevoegd worden.',
'webhooks_help_bitbucket' => 'Voor automatische builds wanneer nieuwe commits worden gepusht, dient onderstaande URL
als "POST" service in de in de
<a href="https://bitbucket.org/%s/admin/services">

View file

@ -99,6 +99,7 @@ od wybranego kodu źródłowego platformy hostingowej.',
'github' => 'GitHub',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'gogs' => 'Gogs',
'remote' => 'Zdalny URL ',
'local' => 'Lokalna Ścieżka ',
'hg' => 'Mercurial',
@ -148,6 +149,9 @@ od wybranego kodu źródłowego platformy hostingowej.',
'webhooks_help_gitlab' => 'Aby automatycznie uruchomić nową budowę po wysłaniu commitów dodaj poniższy adres URL
jako "WebHook URL" w sekcji Web Hook Twojego repozytoria GitLab.',
'webhooks_help_gogs' => 'Aby automatycznie uruchomić nową budowę po wysłaniu commitów dodaj poniższy adres URL
jako "WebHook URL" w sekcji Web Hook Twojego repozytoria Gogs.',
'webhooks_help_bitbucket' => 'Aby automatycznie uruchomić nową budowę po wysłaniu commitów, dodaj poniższy adres URL
jako usługę "POST" w sekcji
<a href="https://bitbucket.org/%s/admin/services">

View file

@ -99,6 +99,7 @@ PHPCI',
'remote' => 'Внешний URL',
'local' => 'Локальный путь',
'hg' => 'Mercurial',
'gogs' => 'Gogs',
'svn' => 'Subversion',
'where_hosted' => 'Расположение проекта',
@ -144,6 +145,9 @@ PHPCI',
'webhooks_help_gitlab' => 'Чтобы Автоматически собирать этот проект при публикации новых коммитов, добавьте URL ниже в качестве "WebHook URL"
в разделе "Web Hooks" вашего GitLab репозитория.',
'webhooks_help_gogs' => 'Чтобы Автоматически собирать этот проект при публикации новых коммитов, добавьте URL ниже в качестве "WebHook URL"
в разделе "Web Hooks" вашего Gogs репозитория.',
'webhooks_help_bitbucket' => 'Чтобы Автоматически собирать этот проект при публикации новых коммитов, добавьте URL ниже как "POST" сервис в разделе <a href="https://bitbucket.org/%s/admin/services">
Services</a> вашего Bitbucket репозитория.',

View file

@ -99,6 +99,7 @@ PHPCI',
'bitbucket' => 'Bitbucket',
'gitlab' => 'GitLab',
'remote' => 'Віддалений URL',
'gogs' => 'Gogs',
'local' => 'Локальний шлях',
'hg' => 'Mercurial',
@ -147,6 +148,9 @@ PHPCI',
'webhooks_help_gitlab' => 'Для автоматичної збірки цього проекту, при надходженні нових комітів, додайте наступний URL
у якості нового "WebHook URL" у розділі "Web Hooks" вашого GitLab репозиторію.',
'webhooks_help_gogs' => 'Для автоматичної збірки цього проекту, при надходженні нових комітів, додайте наступний URL
у якості нового "WebHook URL" у розділі "Web Hooks" вашого Gogs репозиторію.',
'webhooks_help_bitbucket' => 'Для автоматичної збірки цього проекту, при надходженні нових комітів, додайте наступний URL
у якості нового "POST" сервісу у розділі
<a href="https://bitbucket.org/%s/admin/services">Services</a>

View file

@ -67,7 +67,7 @@
<div class="col-lg-3 col-md-4 col-sm-4">
<?php if (in_array($project->getType(), array('github', 'gitlab', 'bitbucket'))): ?>
<?php if (in_array($project->getType(), array('github', 'gitlab', 'bitbucket', 'gogs'))): ?>
<div class="box box-info">
<div class="box-header">
<h4 class="box-title"><?php Lang::out('webhooks'); ?></h4>
@ -87,6 +87,11 @@
Lang::out('webhooks_help_gitlab');
break;
case 'gogs':
$url = PHPCI_URL. 'webhook/gogs/' . $project->getId();
Lang::out('webhooks_help_gogs');
break;
case 'bitbucket':
$url = PHPCI_URL . 'webhook/bitbucket/' . $project->getId();
Lang::out('webhooks_help_bitbucket', $project->getReference());

View file

@ -5,7 +5,7 @@ PHPCI is a free and open source (BSD License) continuous integration tool specif
**Current Build Status**
[![Build Status](http://phpci.block8.net/build-status/image/2?branch=master)](http://phpci.block8.net/build-status/view/2?branch=master)
[![Build Status](https://phpci.gitnet.fr//build-status/image/5?branch=master)](https://phpci.gitnet.fr//build-status/image/5?branch=gogs)
**Chat Room**