Commands fixes

This commit is contained in:
Dmitry Khomutov 2017-02-05 11:18:33 +07:00
commit ed532bad7d
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
24 changed files with 100 additions and 479 deletions

View file

@ -1,16 +1,8 @@
<?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\Command;
use PHPCensor\Service\UserService;
use PHPCensor\Helper\Lang;
use PHPCensor\Store\UserStore;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
@ -21,9 +13,7 @@ use Symfony\Component\Console\Question\Question;
/**
* Create admin command - creates an admin user
*
* @author Wogan May (@woganmay)
* @package PHPCI
* @subpackage Console
* @author Wogan May (@woganmay)
*/
class CreateAdminCommand extends Command
{
@ -46,7 +36,7 @@ class CreateAdminCommand extends Command
{
$this
->setName('php-censor:create-admin')
->setDescription(Lang::get('create_admin_user'));
->setDescription('Create an admin user');
}
/**

View file

@ -1,15 +1,7 @@
<?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\Command;
use PHPCensor\Helper\Lang;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\ProjectStore;
use Symfony\Component\Console\Command\Command;
@ -21,9 +13,7 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* Create build command - creates a build for a project
*
* @author Jérémy DECOOL (@jdecool)
* @package PHPCI
* @subpackage Console
* @author Jérémy DECOOL (@jdecool)
*/
class CreateBuildCommand extends Command
{
@ -56,10 +46,10 @@ class CreateBuildCommand extends Command
{
$this
->setName('php-censor:create-build')
->setDescription(Lang::get('create_build_project'))
->addArgument('projectId', InputArgument::REQUIRED, Lang::get('project_id_argument'))
->addOption('commit', null, InputOption::VALUE_OPTIONAL, Lang::get('commit_id_option'))
->addOption('branch', null, InputOption::VALUE_OPTIONAL, Lang::get('branch_name_option'));
->setDescription('Create a build for a project')
->addArgument('projectId', InputArgument::REQUIRED, 'A project ID')
->addOption('commit', null, InputOption::VALUE_OPTIONAL, 'Commit ID to build')
->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'Branch to build');
}
/**
@ -78,9 +68,9 @@ class CreateBuildCommand extends Command
try {
$this->buildService->createBuild($project, $commitId, $branch);
$output->writeln(Lang::get('build_created'));
$output->writeln('Build Created');
} catch (\Exception $e) {
$output->writeln(sprintf('<error>%s</error>', Lang::get('failed')));
$output->writeln('<error>Failed</error>');
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
}

View file

@ -82,10 +82,9 @@ class InstallCommand extends Command
}
$output->writeln('');
$conf = [];
$conf = [];
$conf['b8']['database'] = $db;
$conf['php-censor'] = $this->getConfigInformation($input, $output);
$conf['php-censor'] = $this->getConfigInformation($input, $output);
$this->writeConfigFile($conf);
$this->setupDatabase($output);
@ -375,8 +374,9 @@ class InstallCommand extends Command
]
];
$dbPort = (integer)$dbPort;
if ($dbPort) {
$dbServers[0]['port'] = (integer)$dbPort;
$dbServers[0]['port'] = $dbPort;
}
$db['servers']['read'] = $dbServers;
@ -402,8 +402,8 @@ class InstallCommand extends Command
{
try {
$dns = $db['type'] . ':host=' . $db['servers']['write'][0]['host'];
if (isset($db['servers']['write'][0]['host'])) {
$dns .= ';port=' . (integer)$db['servers']['write'][0]['host'];
if (isset($db['servers']['write'][0]['port'])) {
$dns .= ';port=' . (integer)$db['servers']['write'][0]['port'];
}
$dns .= ';dbname=' . $db['name'];

View file

@ -1,18 +1,10 @@
<?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\Command;
use b8\Store\Factory;
use b8\HttpClient;
use Monolog\Logger;
use PHPCensor\Helper\Lang;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -22,9 +14,7 @@ use PHPCensor\Model\Build;
/**
* Run console command - Poll github for latest commit id
*
* @author Jimmy Cleuren <jimmy.cleuren@gmail.com>
* @package PHPCI
* @subpackage Console
* @author Jimmy Cleuren <jimmy.cleuren@gmail.com>
*/
class PollCommand extends Command
{
@ -43,7 +33,7 @@ class PollCommand extends Command
{
$this
->setName('php-censor:poll-github')
->setDescription(Lang::get('poll_github'));
->setDescription('Poll GitHub to check if we need to start a build.');
}
/**
@ -58,16 +48,16 @@ class PollCommand extends Command
$token = $this->settings['php-censor']['github']['token'];
if (!$token) {
$this->logger->error(Lang::get('no_token'));
$this->logger->error('No GitHub token found');
return;
}
$buildStore = Factory::getStore('Build');
$this->logger->addInfo(Lang::get('finding_projects'));
$this->logger->addInfo('Finding projects to poll');
$projectStore = Factory::getStore('Project');
$result = $projectStore->getWhere();
$this->logger->addInfo(Lang::get('found_n_projects', count($result['items'])));
$this->logger->addInfo(sprintf('Found %d projects', count($result['items'])));
foreach ($result['items'] as $project) {
$http = new HttpClient('https://api.github.com');
@ -77,12 +67,10 @@ class PollCommand extends Command
$last_committer = $commits['body'][0]['commit']['committer']['email'];
$message = $commits['body'][0]['commit']['message'];
$this->logger->info(Lang::get('last_commit_is', $project->getTitle(), $last_commit));
$this->logger->info(sprintf('Last commit to GitHub for %s is %s', $project->getTitle(), $last_commit));
if (!$project->getArchived() && ($project->getLastCommit() != $last_commit && $last_commit != "")) {
$this->logger->info(
Lang::get('adding_new_build')
);
$this->logger->info('Last commit is different to database, adding new build.');
$build = new Build();
$build->setProjectId($project->getId());
@ -102,6 +90,6 @@ class PollCommand extends Command
}
}
$this->logger->addInfo(Lang::get('finished_processing_builds'));
$this->logger->addInfo('Finished processing builds.');
}
}

View file

@ -1,13 +1,5 @@
<?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\Command;
use b8\Store\Factory;
@ -21,9 +13,7 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* Re-runs the last run build.
*
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Console
* @author Dan Cryer <dan@block8.co.uk>
*/
class RebuildCommand extends Command
{

View file

@ -1,29 +1,18 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCensor\Command;
use b8\Store\Factory;
use Monolog\Logger;
use PHPCensor\BuildFactory;
use PHPCensor\Helper\Lang;
use PHPCensor\Logging\OutputLogHandler;
use PHPCensor\Service\BuildService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Console
* @author Dan Cryer <dan@block8.co.uk>
*/
class RebuildQueueCommand extends Command
{
@ -69,7 +58,7 @@ class RebuildQueueCommand extends Command
$store = Factory::getStore('Build');
$result = $store->getByStatus(0);
$this->logger->addInfo(Lang::get('found_n_builds', count($result['items'])));
$this->logger->addInfo(sprintf('Found %d builds', count($result['items'])));
$buildService = new BuildService($store);

View file

@ -1,17 +1,9 @@
<?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\Command;
use b8\Config;
use Monolog\Logger;
use PHPCensor\Helper\Lang;
use PHPCensor\Logging\BuildDBLogHandler;
use PHPCensor\Logging\LoggedBuildContextTidier;
use PHPCensor\Logging\OutputLogHandler;
@ -27,9 +19,7 @@ use PHPCensor\Model\Build;
/**
* Run console command - Runs any pending builds.
*
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Console
* @author Dan Cryer <dan@block8.co.uk>
*/
class RunCommand extends Command
{
@ -62,8 +52,8 @@ class RunCommand extends Command
{
$this
->setName('php-censor:run-builds')
->setDescription(Lang::get('run_all_pending'))
->addOption('debug', null, null, 'Run PHP Censor in Debug Mode');
->setDescription('Run all pending PHP Censor builds')
->addOption('debug', null, null, 'Run PHP Censor in debug mode');
}
/**
@ -90,13 +80,13 @@ class RunCommand extends Command
$running = $this->validateRunningBuilds();
$this->logger->pushProcessor(new LoggedBuildContextTidier());
$this->logger->addInfo(Lang::get('finding_builds'));
$this->logger->addInfo('Finding builds to process');
/** @var BuildStore $store */
$store = Factory::getStore('Build');
$result = $store->getByStatus(Build::STATUS_PENDING, $this->maxBuilds);
$this->logger->addInfo(Lang::get('found_n_builds', count($result['items'])));
$this->logger->addInfo(sprintf('Found %d builds', count($result['items'])));
$builds = 0;
@ -106,7 +96,7 @@ class RunCommand extends Command
// Skip build (for now) if there's already a build running in that project:
if (in_array($build->getProjectId(), $running)) {
$this->logger->addInfo(Lang::get('skipping_build', $build->getId()));
$this->logger->addInfo(sprintf('Skipping Build %d - Project build already in progress.', $build->getId()));
$result['items'][] = $build;
// Re-run build validator:
@ -137,7 +127,7 @@ class RunCommand extends Command
}
$this->logger->addInfo(Lang::get('finished_processing_builds'));
$this->logger->addInfo('Finished processing builds.');
return $builds;
}
@ -164,7 +154,7 @@ class RunCommand extends Command
$start = $build->getStarted()->getTimestamp();
if (($now - $start) > $timeout) {
$this->logger->addInfo(Lang::get('marked_as_failed', $build->getId()));
$this->logger->addInfo(sprintf('Build %d marked as failed due to timeout.', $build->getId()));
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$store->save($build);

View file

@ -1,11 +1,4 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCensor\Command;
@ -17,13 +10,10 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Worker Command - Starts the BuildWorker, which pulls jobs from beanstalkd
*
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Console
* @author Dan Cryer <dan@block8.co.uk>
*/
class WorkerCommand extends Command
{