/** * @covers PHPUnit::execute */ public function testExecute_CreateBuildWithExtra() { $project = new Project(); $project->setType('bitbucket'); $project->setId(101); $returnValue = $this->testedService->createBuild($project, null, null, null, null, array('item1' => 1001)); $this->assertEquals(1001, $returnValue->getExtra('item1')); }
/** * {@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())); } }
/** * 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()); }
/** * 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; }
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; }
/** * 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; }