/** * Constructor. * * @param Integer $groupId Project Id * @param Integer $weeksNumber Statistics duration in weeks * * @return Void */ public function __construct($groupId, $weeksNumber) { $dao = new GitDao(); // TODO: Optionally include presonal forks in repo list $allRepositories = $dao->getProjectRepositoryList($groupId); $um = UserManager::instance(); $user = $um->getCurrentUser(); $repoFactory = new GitRepositoryFactory($dao, ProjectManager::instance()); foreach ($allRepositories as $repo) { $repository = $repoFactory->getRepositoryById($repo['repository_id']); if ($repository->userCanRead($user)) { $this->repoList[] = $repository; } } $this->displayChart = false; $this->weeksNumber = min($weeksNumber, self::MAX_WEEKSNUMBER); // Init some class properties according to 'weeks number' parameter $today = $_SERVER['REQUEST_TIME']; $startPeriod = strtotime("-{$this->weeksNumber} weeks"); $weekInSeconds = self::WEEKS_IN_SECONDS; for ($i = $startPeriod + $weekInSeconds; $i < $today + $weekInSeconds; $i += $weekInSeconds) { $this->dates[] = date('M d', $i); $this->weekNum[] = intval(date('W', $i)); $this->year[] = intval(date('Y', $i)); } }
private function logError(GitRepository $repository, $sysevent_prefix, $log_prefix, Exception $e) { $this->dao->setGerritMigrationError($repository->getId()); $this->error($sysevent_prefix . $e->getMessage()); $this->logger->error($log_prefix . $this->verbalizeParameters(null), $e); $this->sendErrorNotification($repository); }
public function process() { $repo_id = (int) $this->getParameter(0); $remote_server_id = (int) $this->getParameter(1); $this->dao->switchToGerrit($repo_id, $remote_server_id); $repository = $this->repository_factory->getRepositoryById($repo_id); if (!$repository) { $this->warning('Unable to find repository, perhaps it was deleted in the mean time?'); return; } try { $server = $this->server_factory->getServer($repository); $gerrit_template_id = $this->getParameter(2); $gerrit_project = $this->project_creator->createGerritProject($server, $repository, $gerrit_template_id); $this->project_creator->removeTemporaryDirectory(); $repository->getBackend()->updateRepoConf($repository); $this->project_creator->finalizeGerritProjectCreation($server, $repository, $gerrit_template_id); $this->done("Created project {$gerrit_project} on " . $server->getHost()); return true; } catch (Git_Driver_Gerrit_ProjectCreator_ProjectAlreadyExistsException $e) { $this->logError("gerrit: ", "Gerrit failure: ", $e); } catch (Git_Driver_Gerrit_Exception $e) { $this->logError("gerrit: ", "Gerrit failure: ", $e); } catch (Git_Command_Exception $e) { $this->logError("gerrit: ", "Gerrit failure: ", $e); } catch (Exception $e) { $this->logError("", "An error occured while processing event: ", $e); } }
/** * Create a new GitRepository through its backend * * @param GitRepository $repository * @throws Exception */ public function create(GitRepository $repository, GitRepositoryCreator $creator) { if (!$creator->isNameValid($repository->getName())) { throw new Exception($GLOBALS['Language']->getText('plugin_git', 'actions_input_format_error', array($creator->getAllowedCharsInNamePattern(), GitDao::REPO_NAME_MAX_LENGTH))); } $this->assertRepositoryNameNotAlreadyUsed($repository); $id = $this->dao->save($repository); $repository->setId($id); $this->git_system_event_manager->queueRepositoryUpdate($repository); }
/** * @param DataAccessResult $dar * @return GitRepository */ private function getRepositoryFromDar(DataAccessResult $dar) { $repository = null; if ($dar->rowCount() == 1) { $repository = new GitRepository(); $this->dao->hydrateRepositoryObject($repository, $dar->getRow()); } return $repository; }
public function createFromBundle(GitRepository $repository, GitRepositoryCreator $creator, $bundle_path) { if (!$creator->isNameValid($repository->getName())) { throw new Exception($GLOBALS['Language']->getText('plugin_git', 'actions_input_format_error', array($creator->getAllowedCharsInNamePattern(), GitDao::REPO_NAME_MAX_LENGTH))); } $this->assertRepositoryNameNotAlreadyUsed($repository); $id = $this->dao->save($repository); $repository->setId($id); $bundle_path_arg = escapeshellarg($bundle_path); $repository_full_path_arg = escapeshellarg($repository->getFullPath()); $this->system_command->exec("sudo -u gitolite /usr/share/tuleap/plugins/git/bin/gl-clone-bundle.sh {$bundle_path_arg} {$repository_full_path_arg}"); $this->git_system_event_manager->queueRepositoryUpdate($repository); }
/** * Internal method called by SystemEvent_PROJECT_IS_PRIVATE * @param <type> $projectId * @param <type> $isPublic * @return <type> */ public static function changeProjectRepositoriesAccess($projectId, $isPrivate, GitDao $dao, GitRepositoryFactory $factory) { //if the project is private, then no changes may be applied to repositories, //in other words only if project is set to private, its repositories have to be set to private if (empty($isPrivate)) { return; } $repositories = $dao->getProjectRepositoryList($projectId); foreach ($repositories as $repoId => $repoData) { $r = $factory->getRepositoryById($repoId); if (!$r) { continue; } if ($r->getAccess() == GitRepository::PRIVATE_ACCESS) { continue; } $r->setAccess(GitRepository::PRIVATE_ACCESS); $r->changeAccess(); unset($r); } }
/** * Internal method called by SystemEvent_PROJECT_IS_PRIVATE * @param <type> $projectId * @param <type> $isPublic * @return <type> */ public static function changeProjectRepositoriesAccess($projectId, $isPrivate) { //if the project is private, then no changes may be applied to repositories, //in other words only if project is set to private, its repositories have to be set to private if (empty($isPrivate)) { return; } $dao = new GitDao(); $repositories = $dao->getProjectRepositoryList($projectId); if (empty($repositories)) { return false; } foreach ($repositories as $repoId => $repoData) { $r = new GitRepository(); $r->setId($repoId); if (!$r->exists()) { continue; } $newAccess = !empty($isPrivate) ? GitRepository::PRIVATE_ACCESS : GitRepository::PUBLIC_ACCESS; if ($r->getAccess() == $newAccess) { continue; } $r->setAccess($newAccess); $r->changeAccess(); unset($r); } }
/** * * @param Git_RemoteServer_GerritServer $server * @return bool */ public function isServerUsed(Git_RemoteServer_GerritServer $server) { return $this->git_dao->isRemoteServerUsed($server->getId()); }
public function hasGitShellRepositories() { return $this->dao->hasGitShellRepositories(); }
/** * Retrieve git triggers * * @param Array $params Hook parameters * * @return Array */ function retrieveTriggers($params) { if (isset($params['group_id']) && !empty($params['group_id'])) { $project = $this->getProjectManager()->getProject($params['group_id']); if ($project->usesService(GitPlugin::SERVICE_SHORTNAME)) { $repositoryId = ''; $used = array(); $checked = ''; if (isset($params['job_id']) && !empty($params['job_id'])) { $res = $this->getDao()->retrieveTrigger($params['job_id']); if ($res && !$res->isError() && $res->rowCount() == 1) { $row = $res->getRow(); $repositoryId = $row['repository_id']; $checked = 'checked="checked"'; } } else { $res = $this->getDao()->retrieveTriggers($params['group_id']); if ($res && !$res->isError() && $res->rowCount() > 0) { foreach ($res as $row) { $used[$row['job_id']] = true; } } } $dao = new GitDao(); $repositories = $dao->getProjectRepositoryList($params['group_id'], false, false); $selectBox = '<select id="hudson_use_plugin_git_trigger" name="hudson_use_plugin_git_trigger">'; $selectBox .= '<option>' . $GLOBALS['Language']->getText('global', 'none') . '</option>'; foreach ($repositories as $repository) { $nameSpace = ''; if (!empty($repository['repository_namespace'])) { $nameSpace = $repository['repository_namespace'] . "/"; } $selectBox .= '<option value="' . $repository['repository_id'] . '" '; if ($repositoryId == $repository['repository_id']) { $selectBox .= 'selected="selected"'; } $selectBox .= '>' . $nameSpace . $repository['repository_name'] . '</option>'; } $selectBox .= '</select>'; $addForm = '<p> <div id="hudson_use_plugin_git_trigger_checkbox"> <label class="checkbox"> <input name="hudson_use_plugin_git_trigger_checkbox" type="hidden" value="0" /> <input name="hudson_use_plugin_git_trigger_checkbox" onclick="toggle_checkbox()" type="checkbox" ' . $checked . ' value="1" /> Git </label> </div> <div id="hudson_use_plugin_git_trigger_form"> <label for="hudson_use_plugin_git_trigger">' . $GLOBALS['Language']->getText('plugin_git', 'ci_repo_id') . ': </label> ' . $selectBox . ' </div> <script> function toggle_checkbox() { Effect.toggle(\'hudson_use_plugin_git_trigger_form\', \'slide\', { duration: 0.3 }); } Element.toggle(\'hudson_use_plugin_git_trigger_form\', \'slide\', { duration: 0.3 }) </script> </p>'; $editForm = '<label for="hudson_use_plugin_git_trigger">' . $GLOBALS['Language']->getText('plugin_git', 'ci_field_description') . ': </label>' . $selectBox; return array('service' => GitPlugin::SERVICE_SHORTNAME, 'title' => $GLOBALS['Language']->getText('plugin_git', 'ci_trigger'), 'used' => $used, 'add_form' => $addForm, 'edit_form' => $editForm); } } }
public function isRepositoryExistingByName(Project $project, $name) { $path = GitRepository::getPathFromProjectAndName($project, $name); return $this->dao->isRepositoryExisting($project->getID(), $path); }
/** * @return DataAccessResult */ private function getUGroupsForPermission($repository_id, $permission_type) { return $this->dao->getUGroupsByRepositoryPermissions($repository_id, $permission_type); }
public function executeForRepository(Git_Hook_PushDetails $push_details) { $this->dao->logGitPush($push_details->getRepository()->getId(), $push_details->getUser()->getId(), $_SERVER['REQUEST_TIME'], count($push_details->getRevisionList()), $push_details->getRefname(), $push_details->getType(), $push_details->getRefnameType()); }