Beispiel #1
0
 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);
 }
Beispiel #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;
 }
<?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');
 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();
 }
Beispiel #5
0
 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.');
         }
         $availableTags = $github->getRepoApi()->getRepoTags($_POST['username'], $_POST['repo']);
         foreach ($_POST['hash'] as $hash) {
             //TODO error if a submitted tag is already added
             if (!in_array($hash, $availableTags)) {
                 throw new Exception('That is not a tag in your repository.');
             }
             //TODO get plugin.json from each tag here
         }
     } catch (phpGitHubApiRequestException $e) {