Exemplo n.º 1
0
 /**
  * Loops through running.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $runner = new RunCommand($this->logger);
     $runner->setMaxBuilds(1);
     $runner->setDaemon(false);
     /** @var \PHPCI\Store\BuildStore $store */
     $store = Factory::getStore('Build');
     $service = new BuildService($store);
     $lastBuild = array_shift($store->getLatestBuilds(null, 1));
     $service->createDuplicateBuild($lastBuild);
     $runner->run(new ArgvInput(array()), $output);
 }
Exemplo n.º 2
0
 /**
  * {@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('<error>%s</error>', Lang::get('failed')));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     // For verbose mode we want to output all informational and above
     // messages to the symphony output interface.
     if ($input->hasOption('verbose') && $input->getOption('verbose')) {
         $this->logger->pushHandler(new OutputLogHandler($this->output, Logger::INFO));
     }
     $store = Factory::getStore('Build');
     $result = $store->getByStatus(0);
     $this->logger->addInfo(Lang::get('found_n_builds', count($result['items'])));
     $buildService = new BuildService($store);
     while (count($result['items'])) {
         $build = array_shift($result['items']);
         $build = BuildFactory::getBuild($build);
         $this->logger->addInfo('Added build #' . $build->getId() . ' to queue.');
         $buildService->addBuildToQueue($build);
     }
 }
Exemplo n.º 4
0
 /**
  * Delete a build.
  */
 public function delete($buildId)
 {
     $this->requireAdmin();
     $build = BuildFactory::getBuildById($buildId);
     if (empty($build)) {
         throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
     }
     $this->buildService->deleteBuild($build);
     header('Location: ' . PHPCI_URL . 'project/view/' . $build->getProjectId());
     exit;
 }
Exemplo n.º 5
0
 /**
  * Wrapper for creating a new build.
  *
  * @param Project $project
  * @param string $commitId
  * @param string $branch
  * @param string $committer
  * @param string $commitMessage
  * @param array $extra
  *
  * @return array
  *
  * @throws Exception
  */
 protected function createBuild(Project $project, $commitId, $branch, $committer, $commitMessage, array $extra = null)
 {
     // Check if a build already exists for this commit ID:
     $builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId);
     if ($builds['count']) {
         return array('status' => 'ignored', 'message' => sprintf('Duplicate of build #%d', $builds['items'][0]->getId()));
     }
     // If not, create a new build job for it:
     $build = $this->buildService->createBuild($project, $commitId, $branch, $committer, $commitMessage, $extra);
     return array('status' => 'ok', 'buildID' => $build->getID());
 }
Exemplo n.º 6
0
 /**
  * Delete a build.
  */
 public function delete($buildId)
 {
     $this->requireAdmin();
     $build = BuildFactory::getBuildById($buildId);
     if (empty($build)) {
         throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
     }
     $this->buildService->deleteBuild($build);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'project/view/' . $build->getProjectId());
     return $response;
 }
Exemplo n.º 7
0
 /**
  * Delete a build.
  */
 public function delete($buildId)
 {
     if (empty($_SESSION['user']) || !$_SESSION['user']->getIsAdmin()) {
         throw new \Exception('You do not have permission to do that.');
     }
     $build = BuildFactory::getBuildById($buildId);
     if (empty($build)) {
         throw new NotFoundException('Build with ID: ' . $buildId . ' does not exist.');
     }
     $this->buildService->deleteBuild($build);
     header('Location: ' . PHPCI_URL . 'project/view/' . $build->getProjectId());
     exit;
 }
Exemplo n.º 8
0
 /**
  * Create a new pending build for a project.
  */
 public function build($projectId, $branch = '')
 {
     /* @var \PHPCI\Model\Project $project */
     $project = $this->projectStore->getById($projectId);
     if (empty($branch)) {
         $branch = $project->getBranch();
     }
     if (empty($project)) {
         throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
     }
     $email = $_SESSION['phpci_user']->getEmail();
     $build = $this->buildService->createBuild($project, null, urldecode($branch), $email);
     header('Location: ' . PHPCI_URL . 'build/view/' . $build->getId());
     exit;
 }
Exemplo n.º 9
0
 protected function createBuild($projectId, $commitId, $branch, $committer, $commitMessage, $extra = null)
 {
     // Check if a build already exists for this commit ID:
     $builds = $this->buildStore->getByProjectAndCommit($projectId, $commitId);
     if ($builds['count']) {
         return true;
     }
     $project = $this->projectStore->getById($projectId);
     if (empty($project)) {
         throw new \Exception('Project does not exist:' . $projectId);
     }
     // If not, create a new build job for it:
     $build = $this->buildService->createBuild($project, $commitId, $branch, $committer, $commitMessage, $extra);
     $build = BuildFactory::getBuild($build);
     // Send a status postback if the build type provides one:
     $build->sendStatusPostback();
     return true;
 }
Exemplo n.º 10
0
 /**
  * Create a new pending build for a project.
  */
 public function build($projectId, $branch = '')
 {
     /* @var \PHPCI\Model\Project $project */
     $project = $this->projectStore->getById($projectId);
     if (empty($branch)) {
         $branch = $project->getBranch();
     }
     if (empty($project)) {
         throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
     }
     $email = $_SESSION['phpci_user']->getEmail();
     $build = $this->buildService->createBuild($project, null, urldecode($branch), $email);
     if ($this->buildService->queueError) {
         $_SESSION['global_error'] = Lang::get('add_to_queue_failed');
     }
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'build/view/' . $build->getId());
     return $response;
 }
Exemplo n.º 11
0
 /**
  * @covers PHPUnit::execute
  */
 public function testExecute_DeleteBuild()
 {
     $store = $this->getMock('PHPCI\\Store\\BuildStore');
     $store->expects($this->once())->method('delete')->will($this->returnValue(true));
     $service = new BuildService($store);
     $build = new Build();
     $this->assertEquals(true, $service->deleteBuild($build));
 }