Move BuildFactory to factory.build service.
This commit is contained in:
parent
6aba86e018
commit
da17482a80
8 changed files with 91 additions and 24 deletions
|
|
@ -11,6 +11,7 @@ namespace PHPCI;
|
|||
|
||||
use b8\Store\Factory;
|
||||
use PHPCI\Model\Build;
|
||||
use PHPCI\Store\BuildStore;
|
||||
|
||||
/**
|
||||
* PHPCI Build Factory - Takes in a generic "Build" and returns a type-specific build model.
|
||||
|
|
@ -18,20 +19,30 @@ use PHPCI\Model\Build;
|
|||
*/
|
||||
class BuildFactory
|
||||
{
|
||||
/**
|
||||
* @var BuildStore
|
||||
*/
|
||||
protected $buildStore;
|
||||
|
||||
public function __construct(BuildStore $buildStore)
|
||||
{
|
||||
$this->buildStore = $buildStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $buildId
|
||||
* @return Build
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getBuildById($buildId)
|
||||
public function getBuildById($buildId)
|
||||
{
|
||||
$build = Factory::getStore('Build')->getById($buildId);
|
||||
$build = $this->buildStore->getById($buildId);
|
||||
|
||||
if (empty($build)) {
|
||||
throw new \Exception('Build ID ' . $buildId . ' does not exist.');
|
||||
}
|
||||
|
||||
return self::getBuild($build);
|
||||
return $this->getBuild($build);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +50,7 @@ class BuildFactory
|
|||
* @param Build $base The build from which to get a more specific build type.
|
||||
* @return Build
|
||||
*/
|
||||
public static function getBuild(Build $base)
|
||||
public function getBuild(Build $base)
|
||||
{
|
||||
switch($base->getProject()->getType())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ class RunCommand extends Command
|
|||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var BuildFactory
|
||||
*/
|
||||
protected $buildFactory;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
@ -52,12 +57,14 @@ class RunCommand extends Command
|
|||
protected $isFromDaemon = false;
|
||||
|
||||
/**
|
||||
* @param \Monolog\Logger $logger
|
||||
* @param string $name
|
||||
* @param BuildFactory $buildFactory
|
||||
* @param Logger $logger
|
||||
*/
|
||||
public function __construct(Logger $logger)
|
||||
public function __construct(BuildFactory $buildFactory, Logger $logger)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->buildFactory = $buildFactory;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +102,7 @@ class RunCommand extends Command
|
|||
|
||||
while (count($result['items'])) {
|
||||
$build = array_shift($result['items']);
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build = $this->buildFactory->getBuild($build);
|
||||
|
||||
// Skip build (for now) if there's already a build running in that project:
|
||||
if (!$this->isFromDaemon && in_array($build->getProjectId(), $running)) {
|
||||
|
|
@ -156,7 +163,7 @@ class RunCommand extends Command
|
|||
|
||||
foreach ($running['items'] as $build) {
|
||||
/** @var \PHPCI\Model\Build $build */
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build = $this->buildFactory->getBuild($build);
|
||||
|
||||
$now = time();
|
||||
$start = $build->getStarted()->getTimestamp();
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ class BuildController extends \PHPCI\Controller
|
|||
*/
|
||||
protected $buildService;
|
||||
|
||||
/**
|
||||
* @var BuildFactory
|
||||
*/
|
||||
protected $buildFactory;
|
||||
|
||||
/**
|
||||
* Create the Build controller
|
||||
*
|
||||
|
|
@ -55,12 +60,14 @@ class BuildController extends \PHPCI\Controller
|
|||
Request $request,
|
||||
Response $response,
|
||||
BuildStore $buildStore,
|
||||
BuildService $buildService
|
||||
BuildService $buildService,
|
||||
BuildFactory $buildFactory
|
||||
) {
|
||||
parent::__construct($config, $request, $response);
|
||||
|
||||
$this->buildStore = $buildStore;
|
||||
$this->buildService = $buildService;
|
||||
$this->buildFactory = $buildFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,7 +76,7 @@ class BuildController extends \PHPCI\Controller
|
|||
public function view($buildId)
|
||||
{
|
||||
try {
|
||||
$build = BuildFactory::getBuildById($buildId);
|
||||
$build = $this->buildFactory->getBuildById($buildId);
|
||||
} catch (\Exception $ex) {
|
||||
$build = null;
|
||||
}
|
||||
|
|
@ -127,7 +134,7 @@ class BuildController extends \PHPCI\Controller
|
|||
public function data($buildId)
|
||||
{
|
||||
$response = new JsonResponse();
|
||||
$build = BuildFactory::getBuildById($buildId);
|
||||
$build = $this->buildFactory->getBuildById($buildId);
|
||||
|
||||
if (!$build) {
|
||||
$response->setResponseCode(404);
|
||||
|
|
@ -144,7 +151,7 @@ class BuildController extends \PHPCI\Controller
|
|||
*/
|
||||
public function meta($buildId)
|
||||
{
|
||||
$build = BuildFactory::getBuildById($buildId);
|
||||
$build = $this->buildFactory->getBuildById($buildId);
|
||||
$key = $this->getParam('key', null);
|
||||
$numBuilds = $this->getParam('num_builds', 1);
|
||||
$data = null;
|
||||
|
|
@ -178,7 +185,7 @@ class BuildController extends \PHPCI\Controller
|
|||
*/
|
||||
public function rebuild($buildId)
|
||||
{
|
||||
$copy = BuildFactory::getBuildById($buildId);
|
||||
$copy = $this->buildFactory->getBuildById($buildId);
|
||||
|
||||
if (empty($copy)) {
|
||||
throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
|
||||
|
|
@ -198,7 +205,7 @@ class BuildController extends \PHPCI\Controller
|
|||
{
|
||||
$this->requireAdmin();
|
||||
|
||||
$build = BuildFactory::getBuildById($buildId);
|
||||
$build = $this->buildFactory->getBuildById($buildId);
|
||||
|
||||
if (empty($build)) {
|
||||
throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
|
||||
|
|
|
|||
|
|
@ -44,6 +44,11 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
*/
|
||||
protected $projectStore;
|
||||
|
||||
/**
|
||||
* @var BuildFactory
|
||||
*/
|
||||
protected $buildFactory;
|
||||
|
||||
/**
|
||||
* Create the BuildStatus controller.
|
||||
*
|
||||
|
|
@ -53,6 +58,7 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
* @param BuildStore $buildStore
|
||||
* @param ProjectStore $projectStore
|
||||
* @param HttpClient $shieldsClient
|
||||
* @param BuildFactory $buildFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
|
|
@ -60,13 +66,15 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
Response $response,
|
||||
BuildStore $buildStore,
|
||||
ProjectStore $projectStore,
|
||||
HttpClient $shieldsClient
|
||||
HttpClient $shieldsClient,
|
||||
BuildFactory $buildFactory
|
||||
) {
|
||||
parent::__construct($config, $request, $response);
|
||||
|
||||
$this->buildStore = $buildStore;
|
||||
$this->projectStore = $projectStore;
|
||||
$this->shieldsClient = $shieldsClient;
|
||||
$this->buildFactory = $buildFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -197,7 +205,7 @@ class BuildStatusController extends \PHPCI\Controller
|
|||
$builds = $this->buildStore->getWhere($criteria, 10, 0, array(), $order);
|
||||
|
||||
foreach ($builds['items'] as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build = $this->buildFactory->getBuild($build);
|
||||
}
|
||||
|
||||
return $builds['items'];
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ class HomeController extends \PHPCI\Controller
|
|||
*/
|
||||
protected $buildStore;
|
||||
|
||||
/**
|
||||
* @var BuildFactory
|
||||
*/
|
||||
protected $buildFactory;
|
||||
|
||||
/**
|
||||
* @var ProjectStore
|
||||
*/
|
||||
|
|
@ -45,18 +50,21 @@ class HomeController extends \PHPCI\Controller
|
|||
* @param Response $response
|
||||
* @param BuildStore $buildStore
|
||||
* @param ProjectStore $projectStore
|
||||
* @param BuildFactory $buildFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
Request $request,
|
||||
Response $response,
|
||||
BuildStore $buildStore,
|
||||
ProjectStore $projectStore
|
||||
ProjectStore $projectStore,
|
||||
BuildFactory $buildFactory
|
||||
) {
|
||||
parent::__construct($config, $request, $response);
|
||||
|
||||
$this->buildStore = $buildStore;
|
||||
$this->projectStore = $projectStore;
|
||||
$this->buildFactory = $buildFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,7 +85,7 @@ class HomeController extends \PHPCI\Controller
|
|||
$builds = $this->buildStore->getLatestBuilds(null, 10);
|
||||
|
||||
foreach ($builds as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build = $this->buildFactory->getBuild($build);
|
||||
}
|
||||
|
||||
$this->view->builds = $builds;
|
||||
|
|
@ -158,7 +166,7 @@ class HomeController extends \PHPCI\Controller
|
|||
$view = new b8\View('BuildsTable');
|
||||
|
||||
foreach ($builds['items'] as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build = $this->buildFactory->getBuild($build);
|
||||
}
|
||||
|
||||
$view->builds = $builds['items'];
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ class ProjectController extends PHPCI\Controller
|
|||
*/
|
||||
protected $buildService;
|
||||
|
||||
/**
|
||||
* @var BuildFactory
|
||||
*/
|
||||
protected $buildFactory;
|
||||
|
||||
/**
|
||||
* Create the Project controller.
|
||||
*
|
||||
|
|
@ -64,6 +69,7 @@ class ProjectController extends PHPCI\Controller
|
|||
* @param ProjectStore $projectStore
|
||||
* @param ProjectService $projectService
|
||||
* @param BuildService $buildService
|
||||
* @param BuildFactory $buildFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
|
|
@ -72,7 +78,8 @@ class ProjectController extends PHPCI\Controller
|
|||
BuildStore $buildStore,
|
||||
ProjectStore $projectStore,
|
||||
ProjectService $projectService,
|
||||
BuildService $buildService
|
||||
BuildService $buildService,
|
||||
BuildFactory $buildFactory
|
||||
) {
|
||||
parent::__construct($config, $request, $response);
|
||||
|
||||
|
|
@ -80,6 +87,7 @@ class ProjectController extends PHPCI\Controller
|
|||
$this->projectStore = $projectStore;
|
||||
$this->projectService = $projectService;
|
||||
$this->buildService = $buildService;
|
||||
$this->buildFactory = $buildFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,7 +203,7 @@ class ProjectController extends PHPCI\Controller
|
|||
$view = new b8\View('BuildsTable');
|
||||
|
||||
foreach ($builds['items'] as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build = $this->buildFactory->getBuild($build);
|
||||
}
|
||||
|
||||
$view->builds = $builds['items'];
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ class WebhookController extends \b8\Controller
|
|||
*/
|
||||
protected $buildService;
|
||||
|
||||
/**
|
||||
* @var BuildFactory
|
||||
*/
|
||||
protected $buildFactory;
|
||||
|
||||
/**
|
||||
* Create the Webhook controller.
|
||||
*
|
||||
|
|
@ -57,6 +62,7 @@ class WebhookController extends \b8\Controller
|
|||
* @param BuildStore $buildStore
|
||||
* @param ProjectStore $projectStore
|
||||
* @param BuildService $buildService
|
||||
* @param BuildFactory $buildFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
|
|
@ -64,13 +70,15 @@ class WebhookController extends \b8\Controller
|
|||
Response $response,
|
||||
BuildStore $buildStore,
|
||||
ProjectStore $projectStore,
|
||||
BuildService $buildService
|
||||
BuildService $buildService,
|
||||
BuildFactory $buildFactory
|
||||
) {
|
||||
parent::__construct($config, $request, $response);
|
||||
|
||||
$this->buildStore = $buildStore;
|
||||
$this->projectStore = $projectStore;
|
||||
$this->buildService = $buildService;
|
||||
$this->buildFactory = $buildFactory;
|
||||
}
|
||||
|
||||
/** Handle the action, Ensuring to return a JsonResponse.
|
||||
|
|
@ -382,7 +390,7 @@ class WebhookController extends \b8\Controller
|
|||
|
||||
// If not, create a new build job for it:
|
||||
$build = $this->buildService->createBuild($project, $commitId, $branch, $committer, $commitMessage, $extra);
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$build = $this->buildFactory->getBuild($build);
|
||||
|
||||
// Send a status postback if the build type provides one:
|
||||
$build->sendStatusPostback();
|
||||
|
|
|
|||
10
services.yml
10
services.yml
|
|
@ -25,6 +25,10 @@ services:
|
|||
factory: [%storage.factory%, getStore]
|
||||
arguments:
|
||||
- BuildMeta
|
||||
factory.build:
|
||||
class: PHPCI\BuildFactory
|
||||
arguments:
|
||||
- @storage.build
|
||||
http.request:
|
||||
class: b8\Http\Request
|
||||
arguments: []
|
||||
|
|
@ -59,6 +63,7 @@ services:
|
|||
- @http.response
|
||||
- @storage.build
|
||||
- @storage.project
|
||||
- @factory.build
|
||||
application.controller.project:
|
||||
class: PHPCI\Controller\ProjectController
|
||||
arguments:
|
||||
|
|
@ -69,6 +74,7 @@ services:
|
|||
- @storage.project
|
||||
- @service.project
|
||||
- @service.build
|
||||
- @factory.build
|
||||
application.controller.build:
|
||||
class: PHPCI\Controller\BuildController
|
||||
arguments:
|
||||
|
|
@ -77,6 +83,7 @@ services:
|
|||
- @http.response
|
||||
- @storage.build
|
||||
- @service.build
|
||||
- @factory.build
|
||||
application.controller.buildstatus:
|
||||
class: PHPCI\Controller\BuildStatusController
|
||||
arguments:
|
||||
|
|
@ -86,6 +93,7 @@ services:
|
|||
- @storage.build
|
||||
- @storage.project
|
||||
- @http_client.shields
|
||||
- @factory.build
|
||||
application.controller.user:
|
||||
class: PHPCI\Controller\UserController
|
||||
arguments:
|
||||
|
|
@ -124,6 +132,7 @@ services:
|
|||
- @storage.build
|
||||
- @storage.project
|
||||
- @service.build
|
||||
- @factory.build
|
||||
service.build:
|
||||
class: PHPCI\Service\BuildService
|
||||
arguments: [@storage.build]
|
||||
|
|
@ -164,6 +173,7 @@ services:
|
|||
console.command.run:
|
||||
class: PHPCI\Command\RunCommand
|
||||
arguments:
|
||||
- @factory.build
|
||||
- @console.logger
|
||||
console.command.rebuild:
|
||||
class: PHPCI\Command\RebuildCommand
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue