Пример #1
0
 protected function addRepo($username, $name)
 {
     $repo = $this->getRepository('Repo')->findOneByUsernameAndName($username, $name);
     if ($repo) {
         return $repo;
     }
     $github = new \phpGithubApi();
     $github->setRequest(new Github\Request());
     $githubRepo = new Github\Repo($github, new Output());
     if (!($repo = $githubRepo->update(Repo::create($username . '/' . $name)))) {
         return false;
     }
     if (!($user = $this->getUserRepository()->findOneByName($username))) {
         $githubUser = new Github\User(new \phpGithubApi(), new Output());
         if (!($user = $githubUser->import($username))) {
             return false;
         }
     }
     $user->addRepo($repo);
     $dm = $this->container->getDoctrine_Orm_DefaultEntityManagerService();
     $dm->persist($repo);
     $dm->persist($user);
     $dm->flush();
     return $repo;
 }
Пример #2
0
 public function getContributorNames(Entity\Repo $repo)
 {
     try {
         $contributors = $this->github->getRepoApi()->getRepoContributors($repo->getUsername(), $repo->getName());
     } catch (\phpGitHubApiRequestException $e) {
         if (404 == $e->getCode()) {
             return array();
         }
         throw $e;
     }
     $names = array();
     foreach ($contributors as $contributor) {
         if ($repo->getUsername() != $contributor['login']) {
             $names[] = $contributor['login'];
         }
     }
     return $names;
 }
Пример #3
0
 protected function searchReposOnGoogle(array $repos, $limit)
 {
     $this->output->write('Search on Google');
     $maxBatch = 5;
     $maxPage = 5;
     $pageNumber = 1;
     for ($batch = 1; $batch <= $maxBatch; $batch++) {
         for ($page = 1; $page <= $maxPage; $page++) {
             $url = sprintf('http://www.google.com/search?q=%s&start=%d', urlencode('site:github.com Symfony2 Bundle'), 1 === $pageNumber ? '' : $pageNumber);
             $crawler = $this->browser->request('GET', $url);
             $links = $crawler->filter('#center_col ol li h3 a');
             if (0 != $links->count()) {
                 $this->output->write('.');
             } else {
                 $this->output->write(sprintf(' - No link - [%s]', $this->browser->getResponse()->getStatus()));
                 break 2;
             }
             foreach ($links->extract('href') as $url) {
                 if (!preg_match('#^http://github.com/([\\w-]+/[\\w-]+).*$#', $url, $match)) {
                     continue;
                 }
                 $repo = Repo::create($match[1]);
                 $alreadyFound = false;
                 foreach ($repos as $_repo) {
                     if ($repo->getName() == $_repo->getName()) {
                         $alreadyFound = true;
                         break;
                     }
                 }
                 if (!$alreadyFound) {
                     $repos[] = $repo;
                     $this->output->write(sprintf('!'));
                 }
             }
             $pageNumber++;
             usleep(500 * 1000);
         }
         $this->output->write(sprintf('%d/%d', 10 * ($pageNumber - 1), $maxBatch * $maxPage * 10));
         sleep(2);
     }
     $this->output->writeLn(' DONE');
     return $repos;
 }