private function getEvent(GitRepository $repository) { if (!isset($this->cache[$repository->getId()])) { $this->cache[$repository->getId()] = $this->dao->getSystemEventForRepository($repository->getId()); } return $this->cache[$repository->getId()]; }
private function getView() { if (empty($_REQUEST['a'])) { $_REQUEST['a'] = 'summary'; } else { if ($_REQUEST['a'] === 'blobdiff' && isset($_REQUEST['jenkins']) && $_REQUEST['jenkins'] === 'true') { $this->inverseURLArgumentsForGitPhpDiff(); } } set_time_limit(300); $_GET['a'] = $_REQUEST['a']; $_REQUEST['group_id'] = $this->repository->getProjectId(); $_REQUEST['repo_id'] = $this->repository->getId(); $_REQUEST['repo_name'] = $this->repository->getFullName(); $_GET['p'] = $_REQUEST['repo_name'] . '.git'; $_REQUEST['repo_path'] = $this->repository->getPath(); $_REQUEST['project_dir'] = $this->repository->getProject()->getUnixName(); $_REQUEST['git_root_path'] = $this->repository->getGitRootPath(); $_REQUEST['action'] = 'view'; $this->preSanitizeRequestForGitphp(); if (empty($_REQUEST['noheader'])) { echo '<div id="gitphp" class="plugin_git_gitphp">'; } include $this->getGitPhpIndexPath(); if (empty($_REQUEST['noheader'])) { echo '</div>'; } }
public function updateRepositoryMirrors(GitRepository $repository, array $mirror_ids) { if ($this->mirror_data_mapper->doesAllSelectedMirrorIdsExist($mirror_ids) && $this->mirror_data_mapper->unmirrorRepository($repository->getId()) && $this->mirror_data_mapper->mirrorRepositoryTo($repository->getId(), $mirror_ids)) { $this->history_dao->groupAddHistory("git_repo_mirroring_update", $repository->getName(), $repository->getProjectId()); return true; } return false; }
private function getRemoteRepositoryInfoError() { $date = DateHelper::timeAgoInWords($this->project_creator_status->getEventDate($this->repository), false, true); $url = GIT_BASE_URL . '/?action=repo_management&group_id=' . $this->repository->getProjectId() . '&repo_id=' . $this->repository->getId() . '&pane=gerrit'; $html = ''; $html .= '<div class="alert alert-error gerrit_url">'; $html .= $GLOBALS['Language']->getText('plugin_git', 'delegated_to_gerrit_error', array($date, $url), CODENDI_PURIFIER_DISABLED); $html .= '</div>'; return $html; }
private function launchForRepository(GitRepository $repository) { $res = $this->dao->retrieveTriggersPathByRepository($repository->getId()); if ($res && !$res->isError() && $res->rowCount() > 0) { foreach ($res as $row) { try { $this->jenkins_client->setToken($row['token'])->launchJobBuild($row['job_url']); } catch (Exception $exception) { $this->logger->error(__CLASS__ . '[' . $repository->getId() . '] ' . $exception->getMessage()); } } } }
/** * Get Item wrapper * * @param GitRepository $repo the string representation of the item * @param string $inner the string representation of the item * * @return string the $inner encapsulated in its own wrapper */ protected function getItemWrapper(GitRepository $repo, $inner) { if ($repo->getBackend() instanceof Git_Backend_Gitolite) { return '<option value="' . $repo->getId() . '">' . $inner . '</option>'; } return ''; }
/** * @param GitRepository $repository * @return string the base url to access the git repository regarding plugin configuration */ public function getRepositoryBaseUrl(GitRepository $repository) { if ($this->git_plugin->areFriendlyUrlsActivated()) { return GIT_BASE_URL . '/' . $repository->getProject()->getUnixName() . '/' . $repository->getFullName(); } else { return GIT_BASE_URL . '/index.php/' . $repository->getProjectId() . '/view/' . $repository->getId() . '/'; } }
private function canBeReadByAnonymous(GitRepository $repository) { $ugroup_ids = $this->permissions_manager->getAuthorizedUgroupIds($repository->getId(), Git::PERM_READ); foreach ($ugroup_ids as $ugroup_id) { if ($ugroup_id == ProjectUGroup::ANONYMOUS) { return true; } } return false; }
private function sendErrorNotification(GitRepository $repository) { $user = $this->getRequester(); if (!$user->isAnonymous()) { $factory = new BaseLanguageFactory(); $language = $factory->getBaseLanguage($user->getLocale()); $url = get_server_url() . GIT_BASE_URL . '/?action=repo_management&group_id=' . $repository->getProjectId() . '&repo_id=' . $repository->getId() . '&pane=gerrit'; $notification = new Notification(array($user->getEmail()), $language->getText('plugin_git', 'delegated_to_gerrit_error_mail_subject', array($repository->getFullName())), $language->getText('plugin_git', 'delegated_to_gerrit_error_mail_body', array($repository->getFullName(), $url)), $language->getText('plugin_git', 'delegated_to_gerrit_error_mail_body', array($repository->getFullName(), $url)), $url, 'git'); $this->mail_builder->buildAndSendEmail($repository->getProject(), $notification, new MailEnhancer()); } }
/** @return bool */ public function areRegisteredUsersAllowedTo($permission_type, GitRepository $repository) { if ($permission_type == Git::SPECIAL_PERM_ADMIN) { return false; } foreach ($this->permissions_manager->getAuthorizedUgroups($repository->getId(), $permission_type) as $row) { if ($row['ugroup_id'] == ProjectUGroup::REGISTERED || $row['ugroup_id'] == ProjectUGroup::ANONYMOUS || $row['ugroup_id'] == ProjectUGroup::AUTHENTICATED) { return true; } } }
private function getOptions(Project $project, $permission) { $user_groups = $this->user_group_factory->getAllForProject($project); $options = array(); $selected_values = $this->permissions_manager->getAuthorizedUGroupIdsForProject($project, $this->repository->getId(), $permission); foreach ($user_groups as $ugroup) { if ($ugroup->getId() == ProjectUGroup::ANONYMOUS && $permission !== Git::PERM_READ) { continue; } $selected = in_array($ugroup->getId(), $selected_values) ? 'selected="selected"' : ''; $options[] = array('value' => $ugroup->getId(), 'label' => $ugroup->getName(), 'selected' => $selected); } return $options; }
private function getHeader() { $html = ''; $repoId = $this->repository->getId(); $creator = $this->repository->getCreator(); $parent = $this->repository->getParent(); $access = $this->repository->getAccess(); $creatorName = ''; if (!empty($creator)) { $creatorName = UserHelper::instance()->getLinkOnUserFromUserId($creator->getId()); } // Access type $accessType = $this->getAccessType($access, $this->repository->getBackend() instanceof Git_Backend_Gitolite); $html .= '<h1>' . $accessType . $this->repository->getFullName() . '</h1>'; if (!empty($parent)) { $html .= '<div id="plugin_git_repo_parent">'; $html .= $GLOBALS['Language']->getText('plugin_git', 'view_repo_parent_' . $this->repository->getBackendType(), $parent->getHTMLLink($this->url_manager)); $html .= '</div>'; } return $html; }
public function test(GitRepository $compare) { return $compare->getId() === $this->repository_id; }
private function displayTab($pane) { echo '<li class="' . ($this->current_pane == $pane->getIdentifier() ? 'active' : '') . '">'; $url = GIT_BASE_URL . '/?' . http_build_query(array('action' => 'repo_management', 'group_id' => $this->repository->getProjectId(), 'repo_id' => $this->repository->getId(), 'pane' => $pane->getIdentifier())); echo '<a href="' . $url . '">' . $pane->getTitle() . '</a></li>'; }
private function areThereAnyChanges(GitRepository $repository, array $mirror_ids, array $current_mirror_ids_per_repository) { $current_mirrors = array(); if (isset($current_mirror_ids_per_repository[$repository->getId()])) { $current_mirrors = $current_mirror_ids_per_repository[$repository->getId()]; } return count(array_diff($mirror_ids, $current_mirrors)) > 0 || count(array_diff($current_mirrors, $mirror_ids)) > 0; }
public function isInitialized(GitRepository $repository) { $masterExists = $this->getDriver()->masterExists($this->getGitRootPath() . '/' . $repository->getPath()); if ($masterExists) { $this->getDao()->initialize($repository->getId()); return true; } else { return false; } }
private function addPermissionsToProjectConf(GitRepository $repository, array $ugroups, $replication_group) { // https://groups.google.com/d/msg/repo-discuss/jTAY2ApcTGU/DPZz8k0ZoUMJ // Project owners are those who own refs/* within that project... which // means they can modify the permissions for any reference in the // project. $ugroup_ids_read = $this->user_finder->getUgroups($repository->getId(), Git::PERM_READ); $ugroup_ids_write = $this->user_finder->getUgroups($repository->getId(), Git::PERM_WRITE); $ugroup_ids_rewind = $this->user_finder->getUgroups($repository->getId(), Git::PERM_WPLUS); $ugroups_read = array(); $ugroups_write = array(); $ugroups_rewind = array(); foreach ($ugroups as $ugroup) { if (in_array($ugroup->getId(), $ugroup_ids_read)) { $ugroups_read[] = $repository->getProject()->getUnixName() . '/' . $ugroup->getNormalizedName(); } if (in_array($ugroup->getId(), $ugroup_ids_write)) { $ugroups_write[] = $repository->getProject()->getUnixName() . '/' . $ugroup->getNormalizedName(); } if (in_array($ugroup->getId(), $ugroup_ids_rewind)) { $ugroups_rewind[] = $repository->getProject()->getUnixName() . '/' . $ugroup->getNormalizedName(); } } if ($this->shouldAddRegisteredUsersToGroup($repository, Git::PERM_READ, $ugroup_ids_read)) { $ugroups_read[] = self::GROUP_REGISTERED_USERS; } if ($this->shouldAddRegisteredUsersToGroup($repository, Git::PERM_WRITE, $ugroup_ids_write)) { $ugroups_write[] = self::GROUP_REGISTERED_USERS; } if ($this->shouldAddRegisteredUsersToGroup($repository, Git::PERM_WPLUS, $ugroup_ids_rewind)) { $ugroups_rewind[] = self::GROUP_REGISTERED_USERS; } $this->addToSection('refs', 'read', "group {$replication_group}"); foreach ($ugroups_read as $ugroup_read) { $this->addToSection('refs/heads', 'read', "group {$ugroup_read}"); $this->addToSection('refs/heads', 'label-Code-Review', "-1..+1 group {$ugroup_read}"); } foreach ($ugroups_write as $ugroup_write) { $this->addToSection('refs/heads', 'read', "group {$ugroup_write}"); $this->addToSection('refs/heads', 'create', "group {$ugroup_write}"); $this->addToSection('refs/heads', 'forgeAuthor', "group {$ugroup_write}"); $this->addToSection('refs/heads', 'label-Code-Review', "-2..+2 group {$ugroup_write}"); $this->addToSection('refs/heads', 'label-Verified', "-1..+1 group {$ugroup_write}"); $this->addToSection('refs/heads', 'submit', "group {$ugroup_write}"); $this->addToSection('refs/heads', 'push', "group {$ugroup_write}"); $this->addToSection('refs/heads', 'pushMerge', "group {$ugroup_write}"); } foreach ($ugroups_rewind as $ugroup_rewind) { $this->addToSection('refs/heads', 'push', "+force group {$ugroup_rewind}"); } foreach ($ugroups_read as $ugroup_read) { $this->addToSection('refs/for/refs/heads', 'push', "group {$ugroup_read}"); } foreach ($ugroups_write as $ugroup_write) { $this->addToSection('refs/for/refs/heads', 'push', "group {$ugroup_write}"); $this->addToSection('refs/for/refs/heads', 'pushMerge', "group {$ugroup_write}"); } foreach ($ugroups_read as $ugroup_read) { $this->addToSection('refs/tags', 'read', "group {$ugroup_read}"); } foreach ($ugroups_write as $ugroup_write) { $this->addToSection('refs/tags', 'read', "group {$ugroup_write}"); $this->addToSection('refs/tags', 'pushTag', "group {$ugroup_write}"); } }
/** * Configure gitphp output * * @param GitRepository $repository */ public function getView($repository) { include_once 'common/include/Codendi_HTMLPurifier.class.php'; if (empty($_REQUEST['a'])) { $_REQUEST['a'] = 'summary'; } set_time_limit(300); $_GET['a'] = $_REQUEST['a']; $_REQUEST['group_id'] = $this->groupId; $_REQUEST['repo_id'] = $repository->getId(); $_REQUEST['repo_name'] = $repository->getFullName(); $_GET['p'] = $_REQUEST['repo_name'] . '.git'; $_REQUEST['repo_path'] = $repository->getPath(); $_REQUEST['project_dir'] = $repository->getProject()->getUnixName(); $_REQUEST['git_root_path'] = $repository->getGitRootPath(); $_REQUEST['action'] = 'view'; if (empty($_REQUEST['noheader'])) { //echo '<hr>'; echo '<div id="gitphp">'; } include $this->getGitPhpIndexPath(); if (empty($_REQUEST['noheader'])) { echo '</div>'; } }
protected function fetchGitRepositoryRow(GitRepository $repository, $name, $depth) { $trclass = 'boxitem'; $label = $repository->getBasenameHTMLLink($this->url_manager); $description = $repository->getDescription(); $lastPush = ' '; if (isset($this->lastPushes[$repository->getId()])) { $row = $this->lastPushes[$repository->getId()]; $lastPushDate = html_time_ago($row['push_date']); $who = UserHelper::instance()->getLinkOnUserFromUserId($row['user_id']); $lastPush = $GLOBALS['Language']->getText('plugin_git', 'tree_view_by', array($lastPushDate, $who)); } return $this->fetchHTMLRow($trclass, $depth, $label, $description, $lastPush); }
private function markAsDeleted(GitRepository $repository) { $repository->markAsDeleted(); $this->systemEventManager->createEvent('GIT_REPO_DELETE', $repository->getProjectId() . SystemEvent::PARAMETER_SEPARATOR . $repository->getId(), SystemEvent::PRIORITY_MEDIUM); }
public function getRepoAdminUrl() { return '/plugins/git/?action=repo_management&group_id=' . $this->repository->getProjectId() . '&repo_id=' . $this->repository->getId(); }
public function isProjectSetReadOnlyOnGerritOnGoing(GitRepository $repository) { return $this->system_event_manager->isThereAnEventAlreadyOnGoingMatchingFirstParameter(SystemEvent_GIT_GERRIT_PROJECT_READONLY::NAME, $repository->getId()); }
public function delete(GitRepository $repository) { $id = $repository->getId(); $projectId = $repository->getProjectId(); $id = $this->da->escapeInt($id); $projectId = $this->da->escapeInt($projectId); if (empty($id) || empty($projectId)) { throw new GitDaoException($GLOBALS['Language']->getText('plugin_git', 'dao_delete_params')); } $deletionDate = $repository->getDeletionDate(); $projectName = $repository->getProject()->getUnixName(); $backup_path = str_replace('/', '_', $repository->getFullName()); $backup_path .= '_' . strtotime($deletionDate); $backup_path = $projectName . '_' . $backup_path; $backup_path = $this->da->quoteSmart($backup_path); $deletionDate = $this->da->quoteSmart($deletionDate); $query = ' UPDATE ' . $this->getTable() . ' SET ' . self::REPOSITORY_DELETION_DATE . '=' . $deletionDate . ', ' . self::REPOSITORY_BACKUP_PATH . '=' . $backup_path . ' WHERE ' . self::REPOSITORY_ID . '=' . $id . ' AND ' . self::FK_PROJECT_ID . '=' . $projectId; $r = $this->update($query); $ar = $this->da->affectedRows(); if ($r === false || $ar == 0) { throw new GitDaoException($GLOBALS['Language']->getText('plugin_git', 'dao_delete_error') . ' ' . $this->da->isError()); } if ($ar == 1) { return true; } return false; }
/** * On repository deletion, remove notified people in DB. * * As repository is meant to be deleted, there is no need to propagate * change to backend. * * @param GitRepository $repository * * @return Boolean */ public function markRepositoryAsDeleted(GitRepository $repository) { return $this->dao->removeNotification($repository->getId(), null); }
public function getUGroupsRewinders(GitRepository $repository) { return $this->getUGroupsForPermission($repository->getId(), Git::PERM_WPLUS); }
/** * Collect, into an array, logged git pushes matching a given git repository for the given duration. * * @param GitRepository $repository Git repository we want to fetch its pushes * * @return Array */ private function getRepositoryPushesByWeek(GitRepository $repository) { $pushes = array(); $gitLogDao = new Git_LogDao(); foreach ($this->weekNum as $key => $w) { $res = $gitLogDao->getRepositoryPushesByWeek($repository->getId(), $w, $this->year[$key]); if ($res && !$res->isError() && $res->valid()) { $row = $res->getRow(); $pushes[$key] = intval($row['pushes']); if ($pushes[$key] > 0) { $this->displayChart = true; $this->legend = $repository->getFullName(); } } $pushes = array_pad($pushes, $this->weeksNumber, 0); } return $pushes; }
/** * @param GitRepository $repository * @param array $repositor_ids * @return array */ public function searchOtherRepositoriesInSameProjectFromRepositoryList(GitRepository $repository, $repositor_ids) { $project_repositories = array(); $result = $this->getDao()->searchRepositoriesInSameProjectFromRepositoryList($repositor_ids, $repository->getProjectId()); if (!$result) { return $project_repositories; } foreach ($result as $repo) { if ($repo['repository_id'] == $repository->getId()) { continue; } $project_repositories[] = $repo['repository_id']; } return $project_repositories; }
public function __construct(GitPlugin $plugin) { parent::__construct(); $this->userManager = UserManager::instance(); $this->projectManager = ProjectManager::instance(); $this->factory = new GitRepositoryFactory(new GitDao(), $this->projectManager); $matches = array(); if (preg_match_all('/^\\/plugins\\/git\\/index.php\\/(\\d+)\\/([^\\/][a-zA-Z]+)\\/([a-zA-Z\\-\\_0-9]+)\\/\\?{0,1}.*/', $_SERVER['REQUEST_URI'], $matches)) { $this->request->set('group_id', $matches[1][0]); $this->request->set('action', $matches[2][0]); $repo_id = 0; //repository id is passed if (preg_match('/^([0-9]+)$/', $matches[3][0]) === 1) { $repo_id = $matches[3][0]; } else { //get repository by name and group id to retrieve repo id $repo = new GitRepository(); $repo->setName($matches[3][0]); $repo->setProject($this->projectManager->getProject($matches[1][0])); try { $repo->load(); } catch (Exception $e) { $this->addError('Bad request'); $this->redirect('/'); } $repo_id = $repo->getId(); } $this->request->set('repo_id', $repo_id); } $this->plugin = $plugin; $valid = new Valid_GroupId('group_id'); $valid->required(); if ($this->request->valid($valid)) { $this->groupId = (int) $this->request->get('group_id'); } $valid = new Valid_String('action'); $valid->required(); if ($this->request->valid($valid)) { $this->action = $this->request->get('action'); } if (empty($this->action)) { $this->action = 'index'; } if (empty($this->groupId)) { $this->addError('Bad request'); $this->redirect('/'); } $this->projectName = $this->projectManager->getProject($this->groupId)->getUnixName(); if (!PluginManager::instance()->isPluginAllowedForProject($this->plugin, $this->groupId)) { $this->addError($this->getText('project_service_not_available')); $this->redirect('/projects/' . $this->projectName . '/'); } $this->permittedActions = array(); }
public function repository_id() { return $this->repository->getId(); }
/** * @return Git_Mirror_Mirror[] */ public function fetchAllRepositoryMirrors(GitRepository $repository) { if ($repository instanceof GitRepositoryGitoliteAdmin) { return $this->fetchAll(); } $rows = $this->dao->fetchAllRepositoryMirrors($repository->getId()); return $this->mapDataAccessResultToArrayOfMirrors($rows); }