public function executeShow() { $query = $this->getShowQuery('v'); $this->version = $this->getRecord($query); if ($tag = $this->version->githubTag) { $api = new phpGitHubApi(); $this->commits = $api->listBranchCommits('diem-project', 'diem', $this->version->githubTag); } }
public function update(Entity\User $user) { $data = $this->github->getUserApi()->show($user->getName()); $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; }
public function update(Entity\User $user) { try { $data = $this->github->getUserApi()->show($user->getName()); } catch (\phpGitHubApiRequestException $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\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 getGithubCommits() { $api = new phpGitHubApi(); return $api->listBranchCommits($this->getGithubUsername(), $this->getGithubRepo(), 'master'); }
<?php require_once dirname(__FILE__) . '/vendor/lime.php'; require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php'; $t = new lime_test(7); $username = '******'; $repo = 'php-github-api'; $treeSha = '691c2ec7fd0b948042047b515886fec40fe76e2b'; $github = new phpGitHubApi(true); $t->comment('Show tree'); $tree = $github->getObjectApi()->showTree($username, $repo, $treeSha); $t->is_deeply($github->listObjectTree($username, $repo, $treeSha), $tree, 'Both new and BC syntax work'); $firstFile = array_pop($tree); $t->is($firstFile['sha'], '5ac35496a1cbb2a914ff4325e7d6e8cae61f90b9', 'Tree returned with SHA listings'); $t->comment('Show blob'); $blob = $github->getObjectApi()->showBlob($username, $repo, $treeSha, 'CHANGELOG'); $t->is($blob['name'], 'CHANGELOG', 'Returned CHANGELOG blob'); $t->is_deeply($github->showObjectBlob($username, $repo, $treeSha, 'CHANGELOG'), $blob, 'Both new and BC syntax work'); $t->comment('List blobs'); $blobs = $github->getObjectApi()->listBlobs($username, $repo, $treeSha); $t->ok(count($blobs) > 0, 'Returned array of blobs'); $t->is_deeply($github->listObjectBlobs($username, $repo, $treeSha), $blobs, 'Both new and BC syntax work'); $t->comment('Get raw text'); $text = $github->getObjectApi()->getRawData($username, $repo, 'bd25d1e4ea7eab84b856131e470edbc21b6cd66b'); $expected = "tree d978e4755a9ed4e7ca3ebf9ed674dfb95b4af481\nparent e291e9377fd64e08dba556f2dce5b0fc0011430e\nauthor Thibault Duplessis <*****@*****.**> 1266076405 +0100\ncommitter Thibault Duplessis <*****@*****.**> 1266076405 +0100\n\ncreated README.markdown\n"; $t->is($text, $expected, 'Got a blob raw content');
<?php require_once dirname(__FILE__) . '/../../vendor/lime.php'; require_once dirname(__FILE__) . '/../../lib/phpGitHubApi.php'; $t = new lime_test(4); $api = new phpGitHubApi(true); $t->comment('Test ->searchUsers'); $users = $api->searchUsers('diem-project'); $t->is(count($users), 1, 'Found one user'); $t->is(array_keys($users), array('diem-project'), 'Found diem-project user'); $t->comment('Test ->showUser'); $user = $api->showUser('diem-project'); $t->is($user['login'], 'diem-project', 'Found infos about diem-project user'); $message = 'Found no infos about this-user-probably-doesnt-exist user'; try { $user = $api->showUser('this-user-probably-doesnt-exist'); $t->fail($message); } catch (phpGitHubApiRequestException $e) { $t->pass($message); }
<?php require_once dirname(__FILE__) . '/vendor/lime.php'; require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php'; $t = new lime_test(45); $username = '******'; $token = 'fd8144e29b4a85e9487d1cacbcd4e26c'; $github = new phpGitHubApi(true); // search method $t->comment('Search repos'); $repos = $github->getRepoApi()->search('php github api'); $t->ok(count($repos) > 0, 'Found ' . count($repos) . ' repos'); $t->ok(isset($repos[0]['name']), 'First repo name: ' . $repos[0]['name']); $t->comment('Search repos, specify language'); $repos = $github->getRepoApi()->search('github', 'JavaScript'); $t->is($repos[0]['language'], 'JavaScript', 'First repo language is Javascript'); $repos = $github->getRepoApi()->search('github', 'php'); $t->is($repos[0]['language'], 'PHP', 'First repo language is Php'); $firstPageRepo = $repos[0]['name']; $t->comment('Search repos, specify language and start page'); $repos = $github->getRepoApi()->search('github', 'php', 2); $t->isnt($repos[0]['name'], $firstPageRepo); $repos = $github->getRepoApi()->search('github', 'JavaScript'); $t->is($repos[0]['language'], 'JavaScript', 'First repo language is Javascript'); // getUserRepos method $t->comment('Search repos, specify user'); $repos = $github->getRepoApi()->getUserRepos('ornicar'); $t->ok(count($repos) > 20, 'Found ' . count($repos) . ' repos'); $t->ok(isset($repos[0]['name']), 'First repo name: ' . $repos[0]['name']); // show method $t->comment('Getting info on specific repository');
<?php require_once dirname(__FILE__) . '/../../vendor/lime.php'; require_once dirname(__FILE__) . '/../../lib/phpGitHubApi.php'; $t = new lime_test(3); $api = new phpGitHubApi(true); $t->comment('Test ->listObjectTree'); $tree = $api->listObjectTree('ornicar', 'php-github-api', '691c2ec7fd0b948042047b515886fec40fe76e2b'); $firstFile = array_pop($tree); $t->cmp_ok($firstFile['sha'], '!=', null, 'Tree returned with SHA listings'); $blob = $api->showObjectBlob('ornicar', 'php-github-api', '691c2ec7fd0b948042047b515886fec40fe76e2b', 'CHANGELOG'); print_r($blob); $t->is($blob['name'], 'CHANGELOG', 'Returned CHANGELOG blob'); $blobs = $api->listObjectBlobs('ornicar', 'php-github-api', '691c2ec7fd0b948042047b515886fec40fe76e2b'); $t->cmp_ok(count($blobs), '>', 0, 'Returned array of blobs');
<?php require_once dirname(__FILE__) . '/vendor/lime.php'; require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php'; $t = new lime_test(); $username = '******'; $repo = 'php-github-api'; $github = new phpGitHubApi(true); $t->comment('List issues'); $issues = $github->getIssueApi()->getList($username, $repo, 'closed'); $t->is($issues[0]['state'], 'closed', 'Found closed issues'); $t->is_deeply($github->listIssues($username, $repo, 'closed'), $issues, 'Both new and BC syntax work'); $t->comment('Search issues'); $issues = $github->getIssueApi()->search($username, $repo, 'closed', 'documentation'); $t->is($issues[0]['state'], 'closed', 'Found closed issues matching "documentation"'); $t->is_deeply($github->searchIssues($username, $repo, 'closed', 'documentation'), $issues, 'Both new and BC syntax work'); $t->comment('Show issue'); $issue = $github->getIssueApi()->show($username, $repo, 1); $t->is($issue['title'], 'Provide documentation', 'Found issue #1'); $t->is_deeply($github->showIssue($username, $repo, 1), $issue, 'Both new and BC syntax work'); $username = '******'; $token = 'fd8144e29b4a85e9487d1cacbcd4e26c'; $repo = 'php-github-api'; $t->comment('Authenticate ' . $username); $github->authenticate($username, $token); $t->comment('Open a new issue'); $issueTitle = 'Test new issue title ' . time(); $issue = $github->getIssueApi()->open($username, $repo, $issueTitle, 'Test new issue body'); $t->is($issue['title'], $issueTitle, 'Got the new issue'); $t->is($issue['state'], 'open', 'The new issue is open'); $issueNumber = $issue['number'];
public function step3() { Loader::library("3rdparty/github/phpGitHubApi", FRONTEND_DEVELOPER_PACKAGE_HANDLE); $user = $this->post("user"); $repos = $this->post("repos"); $github = new phpGitHubApi(); $api = $github->getRepoApi(); $tags = $api->getRepoTags($user, $repos); $response = new JSONResponse(); $response->setStatus(false); if (!$tags) { $response->setMessage(t("Bad GitHub response. Try again later.")); $response->flush(); } $tags = array_keys((array) $tags); // usort($tags, 'version_compare'); rsort($tags); if (empty($tags)) { $response->setMessage(t("GitHub repository has no tags. At least one tag is required.")); $response->flush(); } $response->setMessage(t("Tag was able to be confirmed.")); $response->setParameters(array("user" => $user, "repos" => $repos, "tag" => array_shift($tags))); $response->setStatus(true); $response->flush(); }
*/ require_once './inc/autoloader.php'; if ($_POST['doCreate']) { if (!$_POST['username']) { throw new Exception('Forgot username.'); } if (!$_POST['password']) { throw new Exception('Forgot password.'); } if (!$_POST['repo']) { throw new Exception('Forgot repo.'); } if (!is_array($_POST['hash']) || count($_POST['hash']) <= 0) { throw new Exception('No tags selected.'); } $github = new phpGitHubApi(); $github->authenticate($_POST['username'], $_POST['password'], phpGitHubApi::AUTH_HTTP_PASSWORD); $userInfo = $github->getUserApi()->show($_POST['username']); $github->deAuthenticate(); //don't need to be auth'd any longer if (!isset($userInfo["private_gist_count"])) { throw new Exception('unauthorized'); } else { try { $repoInfo = $github->getRepoApi()->show($_POST['username'], $_POST['repo']); if ($repoInfo['owner'] != $_POST['username']) { throw new Exception('You are not the owner of this repo.'); } if ($repoInfo['fork'] || $repoInfo['parent']) { throw new Exception('You cannot add a forked repository.'); }
<?php require_once dirname(__FILE__) . '/vendor/lime.php'; require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php'; $t = new lime_test(5); $username = '******'; $repo = 'php-github-api'; $branch = 'master'; $api = new phpGitHubApi(true); $t->comment('Test ->listBranchCommits'); $commits = $api->getCommitApi()->getBranchCommits($username, $repo, $branch); $t->is_deeply($api->listBranchCommits($username, $repo, $branch), $commits, 'Both new and BC syntax work'); $firstCommit = array_pop($commits); $t->ok(isset($firstCommit['message']), 'Found master commits'); $t->comment('Test ->getFileCommits'); $commits = $api->getCommitApi()->getFileCommits($username, $repo, $branch, 'README'); $t->is_deeply($api->listFileCommits($username, $repo, $branch, 'README'), $commits, 'Both new and BC syntax work'); $firstCommit = array_pop($commits); $t->is($firstCommit['message'], 'first commit', 'Found master README commits'); $t->comment('Test ->getCommit'); $commit = $api->getCommitApi()->getCommit($username, $repo, '726eac09a3b44411bd86'); $t->is($commit['message'], 'first commit', 'Found commit 726eac09a3b44411bd86');
<?php require_once dirname(__FILE__) . '/vendor/lime.php'; require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php'; $t = new lime_test(16); $username = '******'; $token = 'fd8144e29b4a85e9487d1cacbcd4e26c'; $github = new phpGitHubApi(true); $t->comment('Search users'); $users = $github->getUserApi()->search($username); $t->is(count($users), 1, 'Found one user'); $t->is(array_keys($users), array($username), 'Found ' . $username . ' user'); $t->is_deeply($github->searchUsers($username), $users, 'Both new and BC syntax work'); $t->comment('Show a user'); $user = $github->getUserApi()->show($username); $t->is($user['login'], $username, 'Found infos about ' . $username . ' user'); $t->is_deeply($github->showUser($username), $user, 'Both new and BC syntax work'); $t->comment('Show a non-existing user'); try { $user = $github->getUserApi()->show('this-user-probably-doesnt-exist'); $t->fail('Found no infos about this-user-probably-doesnt-exist user'); } catch (phpGitHubApiRequestException $e) { $t->pass('Found no infos about this-user-probably-doesnt-exist user'); } $t->comment('Get following users'); $users = $github->getUserApi()->getFollowing('ornicar'); $t->ok(count($users), 'Found ' . 'ornicar' . ' following users'); $t->comment('Get follower users'); $users = $github->getUserApi()->getFollowers('ornicar'); $t->ok(count($users), 'Found ' . 'ornicar' . ' followers users'); $t->comment('Authenticate ' . $username);
<?php require_once dirname(__FILE__) . '/../../vendor/lime.php'; require_once dirname(__FILE__) . '/../../lib/phpGitHubApi.php'; $t = new lime_test(3); $api = new phpGitHubApi(true); $t->comment('Test ->listIssues'); $issues = $api->listIssues('ornicar', 'php-github-api', 'closed'); $t->is($issues[0]['state'], 'closed', 'Found closed issues'); $t->comment('Test ->searchIssues'); $issues = $api->searchIssues('ornicar', 'php-github-api', 'closed', 'documentation'); $t->is($issues[0]['state'], 'closed', 'Found closed issues matching "documentation"'); $issue = $api->showIssue('ornicar', 'php-github-api', 1); $t->is($issue['title'], 'Provide documentation', 'Found issue #1');
/** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { $github = new \phpGitHubApi(); $github->setRequest(new Github\Request()); $githubSearch = new Github\Search($github, new \Goutte\Client(), $output); $githubUser = new Github\User($github, $output); $gitRepoDir = $this->container->getParameter('kernel.cache_dir') . '/repos'; $gitRepoManager = new Git\RepoManager($gitRepoDir); $githubRepo = new Github\Repo($github, $output, $gitRepoManager); $foundRepos = $githubSearch->searchRepos(500, $output); $output->writeLn(sprintf('Found %d repo candidates', count($foundRepos))); $dm = $this->container->get('symfony2bundles.entity_manager'); $repos = array(); foreach ($dm->getRepository('Knplabs\\Symfony2BundlesBundle\\Entity\\Repo')->findAll() as $repo) { $repos[$repo->getFullName()] = $repo; } $users = array(); foreach ($dm->getRepository('Knplabs\\Symfony2BundlesBundle\\Entity\\User')->findAll() as $user) { $users[$user->getName()] = $user; } $validator = $this->container->get('validator'); $counters = array('created' => 0, 'updated' => 0, 'removed' => 0); // create missing repos foreach ($foundRepos as $repo) { if (isset($repos[$repo->getFullName()])) { continue; } $output->write(sprintf('Discover %s:', $repo->getFullName())); if (isset($users[$repo->getUsername()])) { $user = $users[$repo->getUsername()]; } else { $user = $githubUser->import($repo->getUsername()); $users[$user->getName()] = $user; $dm->persist($user); } $user->addRepo($repo); $repos[$repo->getFullName()] = $repo; $dm->persist($repo); $output->writeLn(' ADDED'); ++$counters['created']; } $output->writeln(sprintf('%d created, %d updated, %d removed', $counters['created'], $counters['updated'], $counters['removed'])); $output->writeln('Will now update commits, files and tags'); // Now update repos with more precise GitHub data foreach ($repos as $repo) { if ($dm->getUnitOfWork()->getEntityState($repo) != UnitOfWork::STATE_MANAGED) { continue; } $output->write($repo->getFullName() . str_repeat(' ', 50 - strlen($repo->getFullName()))); if (!$githubRepo->update($repo)) { $output->write(' - Fail, will be removed'); $repo->getUser()->removeRepo($repo); $dm->remove($repo); } $output->writeLn(' ' . $repo->getScore()); } $dm->flush(); $output->writeLn('Will now update contributors'); foreach ($repos as $repo) { if ($dm->getUnitOfWork()->getEntityState($repo) != UnitOfWork::STATE_MANAGED) { continue; } $contributorNames = $githubRepo->getContributorNames($repo); $contributors = array(); foreach ($contributorNames as $contributorName) { if (!isset($users[$contributorName])) { $user = $githubUser->import($contributorName); $users[$user->getName()] = $user; $dm->persist($user); } $contributors[] = $users[$contributorName]; } $output->writeLn(sprintf('%s contributors: %s', $repo->getFullName(), implode(', ', $contributors))); $repo->setContributors($contributors); } $dm->flush(); // Now update users with more precise GitHub data $output->writeLn(sprintf('Will now update %d users', count($users))); foreach ($users as $user) { if ($dm->getUnitOfWork()->getEntityState($user) != UnitOfWork::STATE_MANAGED) { continue; } $output->write($user->getName() . str_repeat(' ', 40 - strlen($user->getName()))); if (!$githubUser->update($user)) { $output->writeLn('Remove user'); $dm->remove($user); } else { $user->recalculateScore(); $output->writeLn('OK, score is ' . $user->getScore()); } } $output->writeLn('Will now flush changes to the database'); $dm->flush(); $output->writeLn('Population complete.'); }
<?php if ($slug == "git") { Content::$forcedTitle = "Git Update"; if (count($params) > 0) { chdir(HR_ROOT); Content::setContent("\n\t\t\t<h1>Updating website from git...</h1>\n\t\t\t<pre>" . `echo Running git reset --hard && git reset --hard 2>&1 && echo Running git pull && git pull` . "</pre><br />\n\t\t\t<h3>Now pulling latest commit information from Github...</h3>\n\t\t"); inclib('github/lib/phpGitHubApi.php'); $phpGH = new phpGitHubApi(); $phpGH->authenticate('lukegb', '3b4e0c11ee0681db035b0e885147e236', phpGitHubAPI::AUTH_HTTP_TOKEN); $latestCommits = $phpGH->getCommitApi()->getBranchCommits('robbiet480', 'hRepo', 'master'); $gitCommit = array('long' => $latestCommits[0]['id'], 'short' => substr($latestCommits[0]['id'], 0, 7), 'userid' => $latestCommits[0]['author']['login'], 'commitdate' => $latestCommits[0]['committed_date']); file_put_contents(HR_ROOT . '/gitcommit.txt', serialize($gitCommit)); Content::append('<p>Last git commit: ' . $gitCommit['long'] . ' by ' . $gitCommit['userid'] . '</p>'); } else { Content::setContent("\n\t\t\t<h1>Authorisation code incorrect or missing</h2>\n\t\t\t<p>Git update did not go through.</p>\n\t\t"); } }
<?php require_once dirname(__FILE__) . '/vendor/lime.php'; require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php'; $t = new lime_test(5); $username = '******'; $token = 'fd8144e29b4a85e9487d1cacbcd4e26c'; $repo = 'php-github-api'; $api = new phpGitHubApi(); $t->comment('Get user with NO authentication'); $user = $api->getUserApi()->show($username); $t->ok(!isset($user['plan']), 'User plan is not available'); $t->comment('Authenticate ' . $username . ' with default authentication method (should be username and token in URL)'); $api->authenticate($username, $token); $t->comment('Get user with authentication'); $user = $api->getUserApi()->show($username); $t->ok(isset($user['plan']), 'User plan is available'); $t->comment('Autentication: ' . $username . ' using HTTP Basic Authentication with token'); $api->authenticate($username, $token, phpGitHubApi::AUTH_HTTP_TOKEN); $user = $api->getUserApi()->show($username); $t->ok(isset($user['plan']), 'User plan is available'); $t->comment('Deauthenticate'); $api->deAuthenticate(); $user = $api->getUserApi()->show($username); $t->ok(!isset($user['plan']), 'User plan is not available'); $t->comment('Authenticate ' . $username . ' with bad token'); $api->authenticate($username, 'bad-token'); $t->comment('Get user with bad authentication'); try { $user = $api->getUserApi()->show($username); $t->fail('Call with bad authentication throws a phpGitHubApiRequestException');
<?php require_once dirname(__FILE__) . '/../../vendor/lime.php'; require_once dirname(__FILE__) . '/../../lib/phpGitHubApi.php'; $t = new lime_test(2); $api = new phpGitHubApi(true); $t->comment('Test ->listBranchCommits'); $commits = $api->listBranchCommits('ornicar', 'php-github-api', 'master'); $firstCommit = array_pop($commits); $t->is($firstCommit['message'], 'first commit', 'Found master commits'); $commits = $api->listFileCommits('ornicar', 'php-github-api', 'master', 'README'); $firstCommit = array_pop($commits); $t->is($firstCommit['message'], 'first commit', 'Found master README commits');