/** * @param sfRequest $request * @param jenkinsKhanUser $user * * @return JenkinsGroupRun * @throws RuntimeException */ public function getJenkinsGroupRun(sfRequest $request, jenkinsKhanUser $user) { $branchName = $request->getParameter('git_branch_slug'); $userId = $user->getUserId(); $groupRun = JenkinsGroupRunPeer::retrieveBySfGuardUserIdAndGitBranchSlug($userId, $branchName); if (null === $groupRun) { throw new RuntimeException(sprintf('Can\'t retrieve JenkinsGroupRun with branch name %s for user %s.', $branchName, $user->getUsername())); } return $groupRun; }
/** * @param sfWebRequest $request * */ public function execute($request) { $branchName = $request->getParameter('git_branch_slug'); $userId = $this->getUser()->getUserId(); $groupRun = JenkinsGroupRunPeer::retrieveBySfGuardUserIdAndGitBranchSlug($userId, $branchName); $this->forward404If(null === $groupRun, sprintf('Can\'t retrieve JenkinsGroupRun with branch name %s and user id %s', $branchName, $userId)); $delayed = $request->getParameter('delayed') == 1; $onlyUnstabled = $request->getParameter('unstabled') == 1; $groupRun->rebuild($this->getJenkins(), $delayed, $onlyUnstabled); JenkinsRunPeer::fillEmptyJobBuildNumber($this->getJenkins(), $this->getUser()->getUserId()); $message = sprintf('The build [%s] has been relaunched', $groupRun->getLabel()); if ($delayed) { $message = sprintf('The jobs of build [%s] have been added to the delayed list', $groupRun->getLabel()); } elseif ($onlyUnstabled) { $message = sprintf('All the jobs of build [%s] have been added to the delayed list', $groupRun->getLabel()); } $this->getUser()->setFlash('info', $message); $this->redirect($this->generateUrl('branch_view', $groupRun)); }
/** * @param sfRequest $request The current sfRequest object * @return mixed A string containing the view name associated with this action */ function execute($request) { $userId = $this->getUser()->getUserId(); $jenkins = $this->getJenkins(); $sortParams = explode('_', $request->getParameter('sort')); $sortType = 'none'; $sortDirection = ''; if (count($sortParams) == 1) { $sortType = strlen($sortParams[0]) ? $sortParams[0] : 'none'; } elseif (count($sortParams) == 2) { list($sortType, $sortDirection) = $sortParams; } if ($request->hasParameter('git_branch_slug')) { $groupRun = JenkinsGroupRunPeer::retrieveBySfGuardUserIdAndGitBranchSlug($userId, $request->getParameter('git_branch_slug')); $this->forward404If(null === $groupRun, sprintf('Unable to find build branch with branch name %s ', $request->getParameter('git_branch_slug'))); $currentGroupId = $groupRun->getId(); } else { $currentGroupId = $request->getParameter('group_run_id'); } $order = $sortDirection == 'desc' ? Criteria::DESC : Criteria::ASC; $query = new JenkinsGroupRunQuery(); $query->findBySfGuardUserId($userId); switch ($sortType) { case 'date': $query->orderByDate($order); break; case 'label': $query->orderByLabel($order); break; default: $query->orderByDate(Criteria::DESC); break; } $groupRuns = $query->find(); $dataGroupRuns = array(); foreach ($groupRuns as $groupRun) { if (null === $currentGroupId) { $currentGroupId = $groupRun->getId(); } /** @var JenkinsGroupRun $groupRun */ $result = $groupRun->getResult($jenkins); $dataGroupRuns[$groupRun->getId()] = array('label' => $groupRun->getLabel(), 'git_branch' => $groupRun->getGitBranch(), 'git_branch_slug' => $groupRun->getGitBranchSlug(), 'date' => $groupRun->getDate('Y-m-d H:i:s'), 'result' => $result, 'result_weight' => $groupRun->getResultWeight($result), 'url_view' => $this->generateUrl('branch_view', $groupRun) . '/sort/' . $sortType . '_' . $sortDirection); } if ($sortType == 'result') { $method = $sortDirection == 'asc' ? 'sortGroupRunsByResultAsc' : 'sortGroupRunsByResultDesc'; uasort($dataGroupRuns, array($this, $method)); } $currentGroupRun = JenkinsGroupRunPeer::retrieveByPK($currentGroupId); $sortMenu = $partial_url_for_sort_direction = $branch_view_url = null; if (null !== $currentGroupRun) { $sortMenu = array('label' => array('label' => 'Name', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/label_' . $sortDirection), 'date' => array('label' => 'Creation date', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/date_' . $sortDirection), 'result' => array('label' => 'Status', 'url' => $this->generateUrl('branch_view', $currentGroupRun) . '/sort/result_' . $sortDirection)); $branch_view_url = $this->generateUrl('branch_view', $currentGroupRun); $partial_url_for_sort_direction = sprintf('%s/sort/%s_', $this->generateUrl('branch_view', $currentGroupRun), $sortType); } $this->setVar('group_runs', $dataGroupRuns); $this->setVar('current_group_run_id', $currentGroupId); $this->setVar('sort_type', $sortType); $this->setVar('sort_direction', $sortDirection); $this->setVar('sort_menu', $sortMenu); $this->setVar('branch_view_url', $branch_view_url); $this->setVar('partial_url_for_sort_direction', $partial_url_for_sort_direction); $this->setVar('enabled_popover', $this->getUser()->getProfile()->getPopoverEnabled()); }