Exemple #1
0
 protected function searchBundlesOnGitHub($query, array $repos, $limit)
 {
     $this->output->write(sprintf('Search "%s" on Github', $query));
     try {
         $page = 1;
         do {
             $found = $this->github->getRepoApi()->search($query, 'php', $page);
             if (empty($found)) {
                 break;
             }
             foreach ($found as $repo) {
                 $name = $repo['username'] . '/' . $repo['name'];
                 if (!$this->isValidBundleName($name)) {
                     continue;
                 }
                 $entity = new Bundle($name);
                 $repos[strtolower($name)] = $entity;
             }
             $page++;
             $this->output->write('...' . count($repos));
         } while (count($repos) < $limit);
     } catch (\Exception $e) {
         $this->output->write(' - ' . $e->getMessage());
     }
     $this->output->writeln('... DONE');
     return $repos;
 }
Exemple #2
0
 /**
  * Get all branches of a project
  *
  * @param string  $project  Name of the project
  * @param string  $path     Path to the project in the repository
  * @param string  $host     Host of the project (Git or Local)
  *
  * @return array  $output   List of branches available in the project
  */
 function getBranches($project, $path, $host)
 {
     if ($host == 'Github') {
         // Project hosted on Github
         $github = new Github_Client();
         $branches = $github->getRepoApi()->getRepoBranches(Configure::read('Ballista.githubAccount'), $project);
         $output = array_keys($branches);
     } else {
         // Project hosted on local server
         if (chdir($path)) {
             exec('git branch', $output);
         } else {
             $this->cakeError('missingPath');
         }
         // Remove * symbol in branch names
         foreach ($output as $key => $item) {
             $output[$key] = preg_replace('/^\\* /', '', $item);
         }
     }
     // Move master to the top of the branches array
     if ($key = array_search(Configure::read('Ballista.master'), $output)) {
         unset($output[$key]);
         array_unshift($output, Configure::read('Ballista.master'));
     }
     return $output;
 }
 protected function searchReposOnGitHub($query, array $repos, $limit)
 {
     $this->output->write(sprintf('Search "%s" on Github', $query));
     try {
         $page = 1;
         do {
             $found = $this->github->getRepoApi()->search($query, 'php', $page);
             if (empty($found)) {
                 break;
             }
             foreach ($found as $repo) {
                 $repos[] = Repo::create($repo['username'] . '/' . $repo['name']);
             }
             $page++;
             $this->output->write('...' . count($repos));
         } while (count($repos) < $limit);
     } catch (\Exception $e) {
         $this->output->write(' - ' . $e->getMessage());
     }
     $this->output->writeLn('... DONE');
     return array_slice($repos, 0, $limit);
 }
 public function search($term)
 {
     $github = new Github_Client();
     $returnArray = array();
     foreach ($github->getRepoApi()->search($term) as $result) {
         $returnResult = new Result();
         $returnResult->name = $result['name'];
         $returnResult->type = "github";
         $returnResult->url = $result['url'];
         $returnArray[] = $returnResult;
     }
     return $returnArray;
 }
 protected function getUserRepositoryTags()
 {
     Loader::library("3rdparty/github3/Github/Autoloader", FRONTEND_DEVELOPER_PACKAGE_HANDLE);
     Github_Autoloader::register();
     $tags = array();
     $username = $this->getUserName();
     if (!empty($username)) {
         $github = new Github_Client();
         $api = $github->getRepoApi();
         $tags = $api->getRepoTags($username, $this->repos);
     }
     return $tags;
 }
 protected function getUserRepositories()
 {
     Loader::library("3rdparty/github3/Github/Autoloader", FRONTEND_DEVELOPER_PACKAGE_HANDLE);
     Github_Autoloader::register();
     $username = $this->getUserName();
     if (empty($username)) {
         return null;
     }
     $github = new Github_Client();
     $api = $github->getRepoApi();
     $repositories = $api->getUserRepos($username);
     $rows = array();
     foreach ($repositories as $repos) {
         $key = $repos["name"];
         $rows[$key] = $repos;
     }
     return $rows;
 }
Exemple #7
0
 public function getContributorNames(Entity\Bundle $bundle)
 {
     try {
         $contributors = $this->github->getRepoApi()->getRepoContributors($bundle->getUsername(), $bundle->getName());
     } catch (\Github_HttpClient_Exception $e) {
         if (404 == $e->getCode()) {
             return array();
         }
         throw $e;
     }
     $names = array();
     foreach ($contributors as $contributor) {
         if ($bundle->getUsername() != $contributor['login']) {
             $names[] = $contributor['login'];
         }
     }
     return $names;
 }
 /**
  * search
  *
  * @author          Eddie Jaoude
  * @param           string $keyword
  * @param           string $language
  * @return           array $results
  *
  */
 public function search($keyword, $language, $sort_by = 'id', $order = 'ASC')
 {
     # filter data
     if (empty($keyword) && empty($language) && empty($sory_by) && empty($order)) {
         throw new Exception('keyword, language, sort_by, order are all required');
     }
     // check cache
     $search_exists = $this->findOneBy(array('keyword' => (string) $keyword, 'language' => (string) $language));
     if (count($search_exists) == 1) {
         $search_id = $search_exists->getId();
     }
     $now = new Zend_Date();
     $now->sub($this->cache, Zend_Date::HOUR);
     if (count($search_exists) != 1 || $now->isLater($search_exists->getUpdatedAt())) {
         # get new data
         $result = array();
         $page = 1;
         $github = new Github_Client();
         while ($repos = $github->getRepoApi()->search($keyword, $language, $page)) {
             $result = array_merge($result, $repos);
             $page++;
         }
         # current date
         $date = new Zend_Date();
         # delete existing repositories
         if (count($search_exists) == 1) {
             $this->deleteSearchAndRepositories($search_exists->getId());
         }
         # save new repositories
         $search = new Default_Model_Search();
         $search->setKeyword($keyword);
         $search->setLanguage($language);
         $date = new Zend_Date();
         $search->setCreatedAt($date->toString('YYYY-MM-dd HH:mm:ss'));
         $search->setUpdatedAt($date->toString('YYYY-MM-dd HH:mm:ss'));
         $this->_em->persist($search);
         $this->_em->flush();
         $search_id = $search->getId();
         foreach ($result as $k => $v) {
             $repository = new Default_Model_Repository();
             $repository->setSearchId($search_id);
             $repository->setType($v['type']);
             $repository->setUsername($v['username']);
             $repository->setPushed($v['pushed']);
             $repository->setHasWiki($v['has_wiki']);
             $repository->setWatchers($v['watchers']);
             $repository->setDescription(!empty($v['description']) ? $v['description'] : '');
             $repository->setOpenIssues($v['open_issues']);
             $repository->setLanguage($v['language']);
             $repository->setFork($v['fork']);
             $repository->setHasIssues($v['has_issues']);
             $repository->setHomepage(!empty($v['homepage']) ? $v['homepage'] : '');
             $repository->setSize($v['size']);
             $repository->setPrivate($v['private']);
             $repository->setFollowers($v['followers']);
             $repository->setName($v['name']);
             $repository->setOwner($v['owner']);
             $repository->setHasDownloads($v['has_downloads']);
             $repository->setPushedAt($v['pushed_at']);
             $repository->setScore($v['score']);
             $repository->setUrl($v['url']);
             $repository->setForks($v['forks']);
             $repository->setCreated($v['created']);
             $repository->setCreatedAt($v['created_at']);
             $repository->setUpdatedAt($date->toString('YYYY-MM-dd HH:mm:ss'));
             $this->_em->persist($repository);
         }
         $this->_em->flush();
     }
     # get data
     $repositories_qb = $this->_em->createQueryBuilder();
     $repositories_query = $repositories_qb->add('select', 'repository')->add('from', 'Default_Model_Repository repository')->add('where', 'repository.search_id = :id')->setParameter('id', $search_id);
     # sort
     switch ($sort_by) {
         case 'id':
             $repositories_query->add('orderBy', 'repository.id DESC');
             break;
         case 'name':
             $repositories_query->add('orderBy', 'repository.name DESC');
             break;
         case 'owner':
             $repositories_query->add('orderBy', 'repository.owner DESC');
             break;
         case 'pushed_at':
             $repositories_query->add('orderBy', 'repository.pushed_at DESC');
             break;
         case 'created_at':
             $repositories_query->add('orderBy', 'repository.created_at DESC');
             break;
         case 'watchers':
             $repositories_query->add('orderBy', 'repository.watchers DESC');
             break;
         case 'forks':
             $repositories_query->add('orderBy', 'repository.forks DESC');
             break;
         case 'issues':
             $repositories_query->add('orderBy', 'repository.open_issues DESC');
             break;
         case 'score':
             $repositories_query->add('orderBy', 'repository.score DESC');
             break;
     }
     $result = $repositories_query->getQuery()->getArrayResult();
     return $result;
 }