public function testInjectApi() { $client = new Github_Client(); $userApiMock = $this->getMockBuilder('Github_ApiInterface')->getMock(); $client->setApi('user', $userApiMock); $this->assertSame($userApiMock, $client->getUserApi()); }
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; }
public function testGetRawData() { $username = '******'; $repo = 'php-github-api'; $sha1 = 'ab9f17c8ed85c0dd9f33ba8d2d61ebb570768158'; $github = new Github_Client(); $data = $github->getObjectApi()->getRawData($username, $repo, $sha1); $this->assertRegexp('/Release version 3\\.1/', $data); }
public function testGetCommits() { $username = '******'; $repo = 'php-github-api'; $branch = 'master'; $github = new Github_Client(); $commits = $github->getCommitApi()->getBranchCommits($username, $repo, $branch); $commit = array_pop($commits); $this->assertArrayHasKey('url', $commit); }
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; }
public function update(Entity\User $user) { try { $data = $this->github->getUserApi()->show($user->getName()); } catch (\Github_HttpClient_Exception $e) { if (404 == $e->getCode()) { // User has been removed return false; } return true; } $user->setEmail(isset($data['email']) ? $data['email'] : null); $user->setFullName(isset($data['name']) ? $data['name'] : null); $user->setCompany(isset($data['company']) ? $data['company'] : null); $user->setLocation(isset($data['location']) ? $data['location'] : null); $user->setBlog(isset($data['blog']) ? $data['blog'] : null); return true; }
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 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; }
/** * Call any path, POST method * Ex: $api->post('repos/show/my-username', array('email' => '*****@*****.**')) * * @param string $path the GitHub path * @param array $parameters POST parameters * @param array $requestOptions reconfigure the request * @return array data returned */ protected function post($path, array $parameters = array(), $requestOptions = array()) { return $this->client->post($path, $parameters, $requestOptions); }
/** * 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; }
/** * Get last commit hash ID of branch * * @param string $project Name of the project in git * @param string $path Path to the project in the repository * @param string $host Type of hosting (Git or Local) * @param string $branch Name of the branch * * @return string $output Last commit hash ID */ function getLastCommitId($project, $path, $host, $branch) { if ($host == 'Github') { // Project hosted on Github $github = new Github_Client(); $commits = $github->getCommitApi()->getBranchCommits(Configure::read('Ballista.githubAccount'), $project, $branch); $output = $commits[0]['id']; } else { // Project hosted on local server if (chdir($path)) { exec('git rev-parse ' . $branch, $commit); } else { $this->cakeError('missingPath'); } $output = $commit[0]; } return $output; }
function getTicket(array $p_aParams = array()) { $github = new Github_Client(); $ticket = $github->getIssueApi()->show('dragoonis', 'ppi-framework', $p_aParams['id']); // ppi_dump($ticket); exit; $ticket['id'] = $ticket['number']; $ticket['status'] = $ticket['state']; $ticket['ticket_type'] = 'bug'; $ticket['severity'] = 'major'; $ticket['created'] = $ticket['created_at']; $ticket['content'] = $ticket['body']; $user = $github->getUserApi()->show($ticket['user']); $ticket['user_fullname'] = $user['name']; $ticket['repo_name'] = 'ppi-framework'; return $ticket; /* $tickets = $this->select() ->columns('t.*, u.first_name user_fn, u.last_name user_ln, uu.first_name user_assigned_fn, uu.last_name user_assigned_ln, c.title category_name') ->from($this->getTableName() . ' t') ->leftJoin('ticket_category c', 't.category_id = c.id') ->leftJoin('users u', 't.user_id=u.id') ->leftJoin('users uu', 't.assigned_user_id=uu.id'); if(isset($p_aParams['keyword']) && $p_aParams['keyword'] != '') { $sSecureSearchKeyword = $this->quote('%'. $p_aParams['keyword'] .'%'); $aOrWhere = array( 't.id = ' . $sSecureSearchKeyword, 't.title LIKE ' . $sSecureSearchKeyword, 'ticket_type LIKE ' . $sSecureSearchKeyword, 't.severity LIKE ' . $sSecureSearchKeyword, 't.status LIKE ' . $sSecureSearchKeyword ); $tickets = $tickets->where(implode(' OR ', $aOrWhere)); } $tickets = $tickets ->where('t.id = ' . $this->quote($p_aParams['id'])) ->order('created desc') ->getList()->fetch(); return $tickets; */ }
protected function addRepo($username, $name) { $repo = $this->getRepository('Repo')->findOneByUsernameAndName($username, $name); if ($repo) { return $repo; } $github = new \Github_Client(); $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 \Github_Client(), 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; }