public function view($projectId) { $project = $this->projectStore->getById($projectId); if (empty($project)) { throw new NotFoundException('Project with id: ' . $projectId . ' not found'); } if (!$project->getAllowPublicStatus()) { throw new NotFoundException('Project with id: ' . $projectId . ' not found'); } $builds = $this->getLatestBuilds($projectId); if (count($builds)) { $this->view->latest = $builds[0]; } $this->view->builds = $builds; $this->view->project = $project; return $this->view->render(); }
/** * {@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())); } }
/** * Fetch a project and check its type. * * @param int $projectId * @param array|string $expectedType * * @return Project * * @throws Exception If the project does not exist or is not of the expected type. */ protected function fetchProject($projectId, $expectedType) { $project = $this->projectStore->getById($projectId); if (empty($projectId)) { throw new Exception('Project does not exist: ' . $projectId); } if (is_array($expectedType) ? !in_array($project->getType(), $expectedType) : $project->getType() !== $expectedType) { throw new Exception('Wrong project type: ' . $project->getType()); } return $project; }
/** * Edit a project. Handles both the form and processing. */ public function edit($projectId) { if (!$_SESSION['user']->getIsAdmin()) { throw new ForbiddenException('You do not have permission to do that.'); } $method = $this->request->getMethod(); $project = $this->projectStore->getById($projectId); if (empty($project)) { throw new NotFoundException('Project with id: ' . $projectId . ' not found'); } $this->config->set('page_title', 'Edit: ' . $project->getTitle()); $values = $project->getDataArray(); $values['key'] = $values['ssh_private_key']; $values['pubkey'] = $values['ssh_public_key']; if ($values['type'] == "gitlab") { $accessInfo = $project->getAccessInformation(); $reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $project->getReference() . ".git"; $values['reference'] = $reference; } if ($method == 'POST') { $values = $this->getParams(); } $form = $this->projectForm($values, 'edit/' . $projectId); if ($method != 'POST' || $method == 'POST' && !$form->validate()) { $view = new b8\View('ProjectForm'); $view->type = 'edit'; $view->project = $project; $view->form = $form; $view->key = null; return $view->render(); } $values = $form->getValues(); $values['ssh_private_key'] = $values['key']; $values['ssh_public_key'] = $values['pubkey']; if ($values['type'] == "gitlab") { preg_match('`^(.*)@(.*):(.*)/(.*)\\.git`', $values['reference'], $matches); $info = array(); $info["user"] = $matches[1]; $info["domain"] = $matches[2]; $values['access_information'] = serialize($info); $values['reference'] = $matches[3] . "/" . $matches[4]; } $project->setValues($values); $project = $this->projectStore->save($project); header('Location: ' . PHPCI_URL . 'project/view/' . $project->getId()); die; }
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; }
/** * Edit a project. Handles both the form and processing. */ public function edit($projectId) { $this->requireAdmin(); $method = $this->request->getMethod(); $project = $this->projectStore->getById($projectId); if (empty($project)) { throw new NotFoundException(Lang::get('project_x_not_found', $projectId)); } $this->layout->title = $project->getTitle(); $this->layout->subtitle = Lang::get('edit_project'); $values = $project->getDataArray(); $values['key'] = $values['ssh_private_key']; $values['pubkey'] = $values['ssh_public_key']; if ($values['type'] == "gitlab") { $accessInfo = $project->getAccessInformation(); $reference = $accessInfo["user"] . '@' . $accessInfo["domain"] . ':' . $accessInfo["port"] . '/' . ltrim($project->getReference(), '/') . ".git"; $values['reference'] = $reference; } if ($method == 'POST') { $values = $this->getParams(); } $form = $this->projectForm($values, 'edit/' . $projectId); if ($method != 'POST' || $method == 'POST' && !$form->validate()) { $view = new b8\View('ProjectForm'); $view->type = 'edit'; $view->project = $project; $view->form = $form; $view->key = $values['pubkey']; return $view->render(); } $title = $this->getParam('title', Lang::get('new_project')); $reference = $this->getParam('reference', null); $type = $this->getParam('type', null); $options = array('ssh_private_key' => $this->getParam('key', null), 'ssh_public_key' => $this->getParam('pubkey', null), 'build_config' => $this->getParam('build_config', null), 'allow_public_status' => $this->getParam('allow_public_status', 0), 'archived' => $this->getParam('archived', 0), 'branch' => $this->getParam('branch', null), 'group' => $this->getParam('group_id', null)); $project = $this->projectService->updateProject($project, $title, $type, $reference, $options); $response = new b8\Http\Response\RedirectResponse(); $response->setHeader('Location', PHPCI_URL . 'project/view/' . $project->getId()); return $response; }