public function getCommits($nb) { $commits = $this->getGitRepo()->getCommits(12); foreach ($commits as $key => $commit) { $commits[$key]['url'] = $this->entity->getGithubUrl() . '/commit/' . $commit['id']; } return $commits; }
protected function getRepo($repoFullName = 'FriendsOfSymfony/UserBundle') { $manager = $this->getManager(); $repo = RepoEntity::create($repoFullName); $gitRepo = $manager->getRepo($repo); return $gitRepo; }
protected function getRepo($repoFullName = 'FriendsOfSymfony/UserBundle') { $dir = sys_get_temp_dir() . '/s2b_git_repos'; $manager = new RepoManager($dir); $repo = RepoEntity::create($repoFullName); $gitRepo = $manager->getRepo($repo); return $gitRepo; }
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; }
public function getRepoDir(RepoEntity $repo) { return $this->dir . '/' . $repo->getUsername() . '/' . $repo->getName(); }
protected function addRepo($username, $name) { $repo = $this->getRepository('Repo')->findOneByUsernameAndName($username, $name); if ($repo) { return $repo; } $github = new \phpGithubApi(); $github->setRequest(new Github\Request()); $gitRepoManager = new Git\RepoManager($this->reposDir); $githubRepo = new Github\Repo($github, new Output(), $gitRepoManager); $repo = $githubRepo->update(Repo::create($username . '/' . $name)); if (!$repo) { return false; } $user = $this->getUserRepository()->findOneByName($username); if (!$user) { $githubUser = new Github\User(new \phpGithubApi(), new Output()); $user = $githubUser->import($username); if (!$user) { return false; } } $user->addRepo($repo); $this->dm->persist($repo); $this->dm->persist($user); $this->dm->flush(); return $repo; }
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; }