public function itAsksToDeleteTheRepositoryFromAllManifests() { expect($this->generator)->removeRepositoryFromManifestFile('*', $this->repository->getPath())->count(2); expect($this->generator)->removeRepositoryFromManifestFile($this->singapour_mirror, $this->repository->getPath())->at(0); expect($this->generator)->removeRepositoryFromManifestFile($this->noida_mirror, $this->repository->getPath())->at(1); $this->manager->triggerDelete($this->repository->getPath()); }
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()]; }
/** * Wrapper for GitRepository for unit testing purpose * * @param array $row data of the repository to instantiate * * @return GitRepository */ protected function getRepository($row) { $r = new GitRepository(); $r->setId($row[GitDao::REPOSITORY_ID]); $r->load(); return $r; }
/** * 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 ''; }
/** * * Behaviour extracted from official email hook prep_for_email() function * * @param GitRepository $repository * @param PFUser $user * @param type $oldrev * @param type $newrev * @param type $refname * @return Git_Hook_PushDetails */ public function getPushDetails(GitRepository $repository, PFUser $user, $oldrev, $newrev, $refname) { $change_type = Git_Hook_PushDetails::ACTION_ERROR; $revision_list = array(); $rev_type = ''; try { if ($oldrev == self::FAKE_EMPTY_COMMIT) { $revision_list = $this->exec_repo->revListSinceStart($refname, $newrev); $change_type = Git_Hook_PushDetails::ACTION_CREATE; } elseif ($newrev == self::FAKE_EMPTY_COMMIT) { $change_type = Git_Hook_PushDetails::ACTION_DELETE; } else { $revision_list = $this->exec_repo->revList($oldrev, $newrev); $change_type = Git_Hook_PushDetails::ACTION_UPDATE; } if ($change_type == Git_Hook_PushDetails::ACTION_DELETE) { $rev_type = $this->exec_repo->getObjectType($oldrev); } else { $rev_type = $this->exec_repo->getObjectType($newrev); } } catch (Git_Command_Exception $exception) { $this->logger->error(__CLASS__ . " {$repository->getFullName()} {$refname} {$oldrev} {$newrev} " . $exception->getMessage()); } return new Git_Hook_PushDetails($repository, $user, $refname, $change_type, $rev_type, $revision_list); }
public function process() { $parameters = $this->getParametersAsArray(); //repo id $repositoryId = ''; if (!empty($parameters[0])) { $repositoryId = $parameters[0]; } else { $this->error('Missing argument repository id'); return false; } //repo access $repositoryAccess = ''; if (!empty($parameters[1])) { $repositoryAccess = $parameters[1]; } else { $this->error('Missing argument repository access'); return false; } //save $repository = new GitRepository(); $repository->setId($repositoryId); try { $repository->load(); $repository->setAccess($repositoryAccess); $repository->changeAccess(); } catch (GitDaoException $e) { $this->error($e->getMessage()); return false; } $this->done(); }
/** * @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() . '/'; } }
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 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 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; }
public function process() { global $sys_allow_restricted_users; $parameters = $this->getParametersAsArray(); $project = null; if (!empty($parameters[0])) { $project = $this->getProject($parameters[0]); } else { $this->error('Missing argument project id'); return false; } $repositoryName = ''; if (!empty($parameters[1])) { $repositoryName = $parameters[1]; } else { $this->error('Missing argument repository name'); return false; } $userId = 0; if (!empty($parameters[2])) { $userId = $parameters[2]; } else { $this->error('Missing argument user id'); return false; } try { $repository = new GitRepository(); $repository->setBackend(Backend::instance('Git', 'GitBackend')); $repository->setDescription('-- Default description --'); //default access is private when restricted users are allowed if ($sys_allow_restricted_users == 1) { $repository->setAccess(GitRepository::PRIVATE_ACCESS); } else { $repository->setAccess(GitRepository::PUBLIC_ACCESS); } $user = null; if (!empty($userId)) { $user = UserManager::instance()->getUserById($userId); } if (!empty($user)) { $repository->setCreator($user); } $repository->setProject($project); $repository->setName($repositoryName); $repository->create(); $this->done(); } catch (GitDaoException $e) { $this->error($e->getMessage()); return false; } catch (GitDriverException $e) { $this->error($e->getMessage()); return false; } catch (GitBackendException $e) { $this->error($e->getMessage()); return false; } catch (Exception $e) { $this->error($e->getMessage()); return false; } }
private function deleteRepo(GitRepository $repository) { try { $repository->delete(); } catch (Exception $e) { $this->error($e->getMessage()); return false; } $this->done(); return true; }
private function makeGerritProjectReadOnly(GitRepository $repository, Git_RemoteServer_GerritServer $server, Project $project) { try { $this->driver_factory->getDriver($server)->makeGerritProjectReadOnly($server, $project->getUnixName() . '/' . $repository->getName()); } catch (Exception $e) { $this->error($e->getMessage() . $e->getTraceAsString()); return false; } $this->done(); return true; }
/** @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; } } }
protected function _GivenAGitRepoWithNameAndNamespace($name, $namespace) { $repository = new GitRepository(); $repository->setName($name); $repository->setNamespace($namespace); $project = new MockProject(); $project->setReturnValue('getUnixName', 'gpig'); $project->setReturnValue('getId', 123); $repository->setProject($project); return $repository; }
public function doValidate($validator, $values) { try { $git = new GitRepository(sprintf('git://github.com/%s/%s.git', $values['user'], $values['repository']), sfConfig::get('app_git_storage_path'), sfConfig::get('app_git_command')); $git->fetch(); $this->gitRepositoryPath = $git->getPath(); } catch (GitRepositoryException $e) { throw new sfValidatorError($validator, 'Problems pulling/updating the repository.'); } return $values; }
public function _itCallsTheRealThing() { $r = new GitRepository(); $r->setName('dusse'); $r->setNamespace('jean_claude'); //$p = new Project(array('unix_group_name' => 'LesBronzes', 'group_id' => 50)); $p = stub('Project')->getUnixName()->returns('LesBronzes'); $r->setProject($p); $driver = new Git_Driver_Gerrit(new Git_Driver_Gerrit_RemoteSSHCommand(new BackendLogger()), new BackendLogger()); $driver->createProject($r); }
/** * Returns a subset of commits ordered from newest to oldest. * * @param $pageNumber * @return Commit[] */ public function getPage($pageNumber) { $this->numberOfCommits = $this->repository->getNumberOfCommits($this->query); $firstCommitIndex = $pageNumber * $this->commitsPerPage; $lastCommitIndex = ($pageNumber + 1) * $this->commitsPerPage; if ($lastCommitIndex >= $this->numberOfCommits) { $this->isLastPage = true; } else { $this->isLastPage = false; } $query = $this->query . ' --skip=' . $firstCommitIndex . ' --max-count=' . $this->commitsPerPage; return $this->repository->log($query); }
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()); } } } }
private function deleteRepo(GitRepository $repository) { $path = $repository->getPath(); try { $this->logger->debug("Deleting repository " . $path); $this->system_event_manager->queueGrokMirrorManifestRepoDelete($path); $repository->delete(); } catch (Exception $e) { $this->error($e->getMessage()); return false; } $this->done(); return true; }
/** * Returns a subset of commits ordered from newest to oldest. * * @param $pageNumber * @return Commit[] */ public function getPage($pageNumber) { $this->numberOfCommits = $this->repository->getNumberOfCommits(); $firstCommitIndex = $pageNumber * $this->commitsPerPage; $lastCommitIndex = ($pageNumber + 1) * $this->commitsPerPage; if ($lastCommitIndex >= $this->numberOfCommits) { $range = sprintf("HEAD~%s", $firstCommitIndex); $this->isLastPage = true; } else { $range = sprintf("HEAD~%s..HEAD~%s", $lastCommitIndex, $firstCommitIndex); $this->isLastPage = false; } return $this->repository->log($range); }
/** * Pushes a tag to a remote repository. * * @param null|string|GitRemote $remote the remote repository to push to. If null, falls back to repository $defaultRemote. * @return string the response from git */ public function push($remote = null) { if (is_null($remote)) { $remote = $this->repository->remote; } return $this->repository->run("push {$remote} tag {$this->name}"); }
/** * Gets a list of commits in this branch * @return GitCommit[] an array of git commits, indexed by hash */ public function getCommits() { if (is_null($this->_commits)) { $this->_commits = array(); $branchName = $this->remote ? $this->remote->name . '/' . $this->name : $this->name; $command = 'log --pretty=format:"%H" ' . $branchName; foreach (explode("\n", $this->repository->run($command)) as $hash) { $hash = trim($hash); if (!$hash) { continue; } $this->_commits[$hash] = new GitCommit($hash, $this->repository); } } return $this->_commits; }
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>'; } }
/** * @return bool */ private function sendMail(GitRepository $repository, MailBuilder $mail_builder, $oldrev, $newrev, $refname) { $mail_raw_output = array(); exec('/usr/share/codendi/plugins/git/hooks/post-receive-email ' . escapeshellarg($oldrev) . ' ' . escapeshellarg($newrev) . ' ' . escapeshellarg($refname), $mail_raw_output); $subject = isset($mail_raw_output[0]) ? $mail_raw_output[0] : self::DEFAULT_MAIL_SUBJECT; $mail_enhancer = new MailEnhancer(); $this->addAdditionalMailHeaders($mail_enhancer, $mail_raw_output); $body = $this->createMailBody($mail_raw_output); $access_link = $repository->getDiffLink($this->repository_url_manager, $newrev); $notification = new Notification($repository->getNotifiedMails(), $subject, '', $body, $access_link, 'Git'); return $mail_builder->buildAndSendEmail($repository->getProject(), $notification, $mail_enhancer); }
private function deleteGerritProject(GitRepository $repository, Git_RemoteServer_GerritServer $server, Project $project, $backend) { try { $this->driver_factory->getDriver($server)->deleteProject($server, $project->getUnixName() . '/' . $repository->getName()); $backend->setGerritProjectAsDeleted($repository); } catch (Exception $e) { $this->error($e->getMessage() . $e->getTraceAsString()); return false; } $this->done(); return true; }
/** * Loads the metadata for the commit */ protected function loadData() { $delimiter = '|||---|||---|||'; $command = 'show --pretty=format:"%an' . $delimiter . '%ae' . $delimiter . '%cd' . $delimiter . '%s' . $delimiter . '%B' . $delimiter . '%N" ' . $this->hash; $response = $this->repository->run($command); $parts = explode($delimiter, $response); $this->_authorName = array_shift($parts); $this->_authorEmail = array_shift($parts); $this->_time = array_shift($parts); $this->_subject = array_shift($parts); $this->_message = array_shift($parts); $this->_notes = array_shift($parts); }
private function getAccessURLs() { $urls = $this->repository->getAccessURL(); if ($this->repository->isMigratedToGerrit()) { $gerrit_user = $this->gerrit_usermanager->getGerritUser($this->current_user); $gerrit_server = $this->gerrit_servers[$this->repository->getRemoteServerId()]; $driver = $this->driver_factory->getDriver($gerrit_server); $gerrit_project = $driver->getGerritProjectName($this->repository); $clone_url = $gerrit_server->getEndUserCloneUrl($gerrit_project, $gerrit_user); $this->prependGerritCloneURL($urls, $clone_url); } return $urls; }
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 getRemoteRepositoryInfo() { /** @var $gerrit_server Git_RemoteServer_GerritServer */ $gerrit_server = $this->gerrit_servers[$this->repository->getRemoteServerId()]; $driver = $this->driver_factory->getDriver($gerrit_server); $gerrit_project = $driver->getGerritProjectName($this->repository); $link = $gerrit_server->getProjectUrl($gerrit_project); $html = ''; $html .= '<div class="alert alert-info gerrit_url">'; $html .= $GLOBALS['Language']->getText('plugin_git', 'delegated_to_gerrit'); $html .= ' <a href="' . $link . '">' . $gerrit_project . '</a>'; $html .= '</div>'; return $html; }