/**
  * View the repository
  *
  */
 function view()
 {
     if ($this->active_repository->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_repository->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->addBreadcrumb(str_excerpt(clean($this->active_repository->getName()), 10), mobile_access_module_get_view_url($this->active_repository));
     $this->addBreadcrumb(lang('View'));
     $per_page = 20;
     $page = intval(array_var($_GET, 'page')) > 0 ? array_var($_GET, 'page') : 1;
     list($commits, $pagination) = Commits::paginateByRepository($this->active_repository, $page, $per_page);
     $commits = group_by_date($commits);
     $this->smarty->assign(array('pagination' => $pagination, 'commits' => $commits, 'pagination_url' => assemble_url('mobile_access_view_repository', array('object_id' => $this->active_repository->getId(), 'project_id' => $this->active_project->getId())), 'page_back_url' => assemble_url('mobile_access_view_project', array('project_id' => $this->active_project->getId()))));
 }
 /**
  * Edit repository
  *
  * @param null
  * @return void
  */
 function edit()
 {
     if (!$this->active_repository->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $repository_data = $this->request->post('repository');
     if (!is_array($repository_data)) {
         $repository_data = array('name' => $this->active_repository->getName(), 'url' => $this->active_repository->getUrl(), 'username' => $this->active_repository->getUsername(), 'password' => $this->active_repository->getPassword(), 'repositorytype' => $this->active_repository->getRepositoryType(), 'updatetype' => $this->active_repository->getUpdateType(), 'visibility' => $this->active_repository->getVisibility());
     }
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_repository->setAttributes($repository_data);
         $this->active_repository->loadEngine($this->active_repository->getRepositoryType());
         $this->repository_engine = new RepositoryEngine($this->active_repository);
         $this->repository_engine->triggerred_by_handler = true;
         $result = $this->repository_engine->testRepositoryConnection();
         if ($result === true) {
             $save = $this->active_repository->save();
             if ($save && !is_error($save)) {
                 db_commit();
                 flash_success(lang('Repository has been successfully updated'));
                 $this->redirectToUrl($this->active_repository->getHistoryUrl());
             } else {
                 db_rollback();
                 $this->smarty->assign('errors', $save);
             }
             //if
         } else {
             db_rollback();
             $errors = new ValidationErrors();
             $errors->addError(lang('Failed to connect to repository: :message', array('message' => $result)));
             $this->smarty->assign('errors', $errors);
         }
         // if
     }
     // if
     js_assign('repository_test_connection_url', assemble_url('repository_test_connection', array('project_id' => $this->active_project->getId())));
     $this->smarty->assign(array('types' => $this->active_repository->types, 'update_types' => $this->active_repository->update_types, 'repository_data' => $repository_data, 'active_repository' => $this->active_repository, 'disable_url_and_type' => instance_of($this->active_repository->getLastCommit(), 'Commit'), 'aid_url' => lang('The path to the existing repository cannot be changed'), 'aid_engine' => lang('Repository type cannot be changed')));
 }
 /**
  * Add a Github repository
  *
  * @return void
  * @return null
  **/
 function add()
 {
     if (!Repository::canAdd($this->logged_user, $this->active_project)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $repository_data = $this->request->post('repository');
     if (!is_array($repository_data)) {
         $repository_data = array('visibility' => $this->active_project->getDefaultVisibility());
     }
     // if
     if ($this->request->isSubmitted()) {
         $repository_data['name'] = trim($repository_data['name']) == '' ? $repository_data['url'] : $repository_data['name'];
         $this->active_repository->setAttributes($repository_data);
         $this->active_repository->setBody(clean(array_var($repository_data, 'url', null)));
         $this->active_repository->setProjectId($this->active_project->getId());
         $this->active_repository->setCreatedBy($this->logged_user);
         $this->active_repository->setState(STATE_VISIBLE);
         $result = $this->active_repository->testRepositoryConnection();
         if ($result === true) {
             $save = $this->active_repository->save();
             if ($save && !is_error($save)) {
                 flash_success(lang('Project repository ":name" has been added successfully'), array('name' => $this->active_repository->getName()));
                 $this->redirectToUrl(github_module_url($this->active_project));
             } else {
                 $save->errors['-- any --'] = $save->errors['body'];
                 $this->smarty->assign('errors', $save);
             }
             //if
         } else {
             $errors = new ValidationErrors();
             $errors->addError(lang('Failed to connect to repository: :message', array('message' => $result)));
             $this->smarty->assign('errors', $errors);
         }
         // if
     }
     // if
     $this->smarty->assign(array('repository_data' => $repository_data));
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider validNameProvider
  */
 public function testValidRepoName($name)
 {
     $config = new Config('/tmp');
     $repo = new Repository($name, $config);
     $this->assertSame($name, $repo->getName());
 }