diff --git a/PHPCI/Command/CreateBuildCommand.php b/PHPCI/Command/CreateBuildCommand.php new file mode 100644 index 00000000..01260080 --- /dev/null +++ b/PHPCI/Command/CreateBuildCommand.php @@ -0,0 +1,85 @@ +projectStore = $projectStore; + $this->buildService = $buildService; + } + + /** + * {@inheritDoc} + */ + protected function configure() + { + $this + ->setName('phpci: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')); + } + + /** + * {@inheritDoc} + */ + public function execute(InputInterface $input, OutputInterface $output) + { + $projectId = $input->getArgument('projectId'); + $commitId = $input->getOption('commit'); + $branch = $input->getOption('branch'); + + $project = $this->projectStore->getById($projectId); + if (empty($project)) { + throw new \InvalidArgumentException('Project does not exist: ' . $projectId); + } + + try { + $this->buildService->createBuild($project, $commitId, $branch); + $output->writeln(Lang::get('build_created')); + } catch (\Exception $e) { + $output->writeln(sprintf('%s', Lang::get('failed'))); + $output->writeln(sprintf('%s', $e->getMessage())); + } + } +} diff --git a/PHPCI/Languages/lang.da.php b/PHPCI/Languages/lang.da.php index 883e52b0..b65f9ef9 100644 --- a/PHPCI/Languages/lang.da.php +++ b/PHPCI/Languages/lang.da.php @@ -338,6 +338,12 @@ Kontrollér venligst nedenstående fejl før du fortsætter.', 'create_admin_user' => 'Tilføj en administrator', 'incorrect_format' => 'Forkert format', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Kør alle PHPCI builds i køen.', 'finding_builds' => 'Finder builds der skal køres', diff --git a/PHPCI/Languages/lang.de.php b/PHPCI/Languages/lang.de.php index 62504310..393459a1 100644 --- a/PHPCI/Languages/lang.de.php +++ b/PHPCI/Languages/lang.de.php @@ -336,6 +336,12 @@ generiert. Um es zu verwenden, fügen Sie einfach den folgenden Public Key im Ab 'create_admin_user' => 'Administratorenbenutzer erstellen', 'incorrect_format' => 'Falsches Format', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Führe alle ausstehenden PHPCI Builds aus.', 'finding_builds' => 'Suche verarbeitbare Builds', diff --git a/PHPCI/Languages/lang.el.php b/PHPCI/Languages/lang.el.php index 5afc6593..e97da6d3 100644 --- a/PHPCI/Languages/lang.el.php +++ b/PHPCI/Languages/lang.el.php @@ -339,6 +339,12 @@ Services του Bitbucket αποθετηρίου σας.', 'create_admin_user' => 'Δημιουργήστε ένα χρήστη διαχειριστή', 'incorrect_format' => 'Λανθασμένη μορφοποίηση', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Εκτελέστε όλες τις εκκρεμείς PHPCI κατασκευές.', 'finding_builds' => 'Αναζήτηση κατασκευών για επεξεργασία', diff --git a/PHPCI/Languages/lang.en.php b/PHPCI/Languages/lang.en.php index 393ef584..19d41cbe 100644 --- a/PHPCI/Languages/lang.en.php +++ b/PHPCI/Languages/lang.en.php @@ -343,6 +343,12 @@ PHPCI', 'create_admin_user' => 'Create an admin user', 'incorrect_format' => 'Incorrect format', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Run all pending PHPCI builds.', 'finding_builds' => 'Finding builds to process', diff --git a/PHPCI/Languages/lang.fr.php b/PHPCI/Languages/lang.fr.php index 6965cb06..a8de5991 100644 --- a/PHPCI/Languages/lang.fr.php +++ b/PHPCI/Languages/lang.fr.php @@ -340,6 +340,12 @@ PHPCI', 'create_admin_user' => 'Créer un utilisateur admin', 'incorrect_format' => 'Format incorrect', + // Create Build Command + 'create_build_project' => 'Créer un build projet', + 'project_id_argument' => 'ID du projet', + 'commit_id_option' => 'ID du commit', + 'branch_name_option' => 'Branche', + // Run Command 'run_all_pending' => 'Démarrage de tout les builds PHPCI en attente.', 'finding_builds' => 'Découverte des builds à traiter', diff --git a/PHPCI/Languages/lang.it.php b/PHPCI/Languages/lang.it.php index db6b23fc..f8f41ea8 100644 --- a/PHPCI/Languages/lang.it.php +++ b/PHPCI/Languages/lang.it.php @@ -342,6 +342,12 @@ PHPCI', 'create_admin_user' => 'Crea un nuovo utente amministrarore', 'incorrect_format' => 'Formato errato', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Esegui tutte le build in attesa su PHPCI.', 'finding_builds' => 'Ricerca delel build da processare', diff --git a/PHPCI/Languages/lang.nl.php b/PHPCI/Languages/lang.nl.php index 38e9466c..f3c0a7c5 100644 --- a/PHPCI/Languages/lang.nl.php +++ b/PHPCI/Languages/lang.nl.php @@ -340,6 +340,12 @@ Gelieve de fouten na te kijken vooraleer verder te gaan.', 'create_admin_user' => 'Administrator-gebruiker aanmaken', 'incorrect_format' => 'Incorrect formaat', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Voer alle wachtende PHPCI builds uit.', 'finding_builds' => 'Zoekt builds om te verwerken', diff --git a/PHPCI/Languages/lang.pl.php b/PHPCI/Languages/lang.pl.php index b4f8430c..37a78fb6 100644 --- a/PHPCI/Languages/lang.pl.php +++ b/PHPCI/Languages/lang.pl.php @@ -341,6 +341,12 @@ Przejrzyj powyższą listę błędów przed kontynuowaniem.', 'create_admin_user' => 'Utwórz admina', 'incorrect_format' => 'Niepoprawny format', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Uruchom wszystkie oczekujące budowy w PHPCI', 'finding_builds' => 'Szukam budów do przetwarzania.', diff --git a/PHPCI/Languages/lang.ru.php b/PHPCI/Languages/lang.ru.php index 931c8910..7627db85 100644 --- a/PHPCI/Languages/lang.ru.php +++ b/PHPCI/Languages/lang.ru.php @@ -336,6 +336,12 @@ PHPCI', 'create_admin_user' => 'Добавить аккаунт администратора', 'incorrect_format' => 'Неверный формат', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Запустить все ожидающие PHPCI сборки.', 'finding_builds' => 'Поиск сборок для запуска', diff --git a/PHPCI/Languages/lang.uk.php b/PHPCI/Languages/lang.uk.php index b080c65a..2b2cc027 100644 --- a/PHPCI/Languages/lang.uk.php +++ b/PHPCI/Languages/lang.uk.php @@ -340,6 +340,12 @@ PHPCI', 'create_admin_user' => 'Створити аккаунт адміністратора', 'incorrect_format' => 'Невірний формат', + // Create Build Command + 'create_build_project' => 'Create a build for a project', + 'project_id_argument' => 'A project ID', + 'commit_id_option' => 'Commit ID to build', + 'branch_name_option' => 'Branch to build', + // Run Command 'run_all_pending' => 'Запустити всі PHPCI збірки, які очікують.', 'finding_builds' => 'Пошук збірок для обробки', diff --git a/Tests/PHPCI/Command/CreateBuildCommandTest.php b/Tests/PHPCI/Command/CreateBuildCommandTest.php new file mode 100644 index 00000000..59395de5 --- /dev/null +++ b/Tests/PHPCI/Command/CreateBuildCommandTest.php @@ -0,0 +1,86 @@ +getMock('PHPCI\\Model\\Project'); + + $projectStoreMock = $this->getMockBuilder('PHPCI\\Store\\ProjectStore') + ->getMock(); + $projectStoreMock->method('getById') + ->will($this->returnValueMap(array( + array(1, 'read', $projectMock), + array(2, 'read', null), + ))); + + $buildServiceMock = $this->getMockBuilder('PHPCI\\Service\\BuildService') + ->disableOriginalConstructor() + ->getMock(); + $buildServiceMock->method('createBuild') + ->withConsecutive( + array($projectMock, null, null, null, null, null), + array($projectMock, '92c8c6e', null, null, null, null), + array($projectMock, null, 'master', null, null, null) + ); + + $this->command = $this->getMockBuilder('PHPCI\\Command\\CreateBuildCommand') + ->setConstructorArgs(array($projectStoreMock, $buildServiceMock)) + ->setMethods(array('reloadConfig')) + ->getMock(); + + $this->application = new Application(); + } + + protected function getCommandTester() + { + $this->application->add($this->command); + + $command = $this->application->find('phpci:create-build'); + $commandTester = new CommandTester($command); + + return $commandTester; + } + + public function testExecute() + { + $commandTester = $this->getCommandTester(); + + $commandTester->execute(array('projectId' => 1)); + $commandTester->execute(array('projectId' => 1, '--commit' => '92c8c6e')); + $commandTester->execute(array('projectId' => 1, '--branch' => 'master')); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testExecuteWithUnknowProjectId() + { + $commandTester = $this->getCommandTester(); + $commandTester->execute(array('projectId' => 2)); + } +} diff --git a/console b/console index a812fc7f..36645768 100755 --- a/console +++ b/console @@ -20,6 +20,8 @@ use PHPCI\Command\InstallCommand; use PHPCI\Command\DaemonCommand; use PHPCI\Command\PollCommand; use PHPCI\Command\CreateAdminCommand; +use PHPCI\Command\CreateBuildCommand; +use PHPCI\Service\BuildService; use Symfony\Component\Console\Application; use b8\Store\Factory; @@ -33,5 +35,6 @@ $application->add(new GenerateCommand); $application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand'))); $application->add(new PollCommand($loggerConfig->getFor('PollCommand'))); $application->add(new CreateAdminCommand(Factory::getStore('User'))); +$application->add(new CreateBuildCommand(Factory::getStore('Project'), new BuildService(Factory::getStore('Build')))); $application->run();