public function build($username, $repository) { $this->repository = new Repository($username, $repository); // repository data $data = $this->client->api('repo')->show($this->repository->username, $this->repository->repository); $this->repository->size = $data['size']; $this->repository->stargazersCount = $data['stargazers_count']; $this->repository->forks = $data['forks']; $this->repository->openIssues = $data['open_issues']; $this->repository->subscribersCount = $data['subscribers_count']; // repository commit activity do { $activity = $this->client->api('repo')->activity($this->repository->username, $this->repository->repository); $responseStatusCode = $this->client->getHttpClient()->getLastResponse()->getStatusCode(); if ($responseStatusCode != 200) { sleep(3); } else { break; } } while (true); $commitsLastYear = array_map(function (array $weekCommits) { return $weekCommits['total']; }, $activity); $this->repository->commitsCount = array_sum($commitsLastYear); $this->repository->commitsLastMonthCount = array_sum(array_slice($commitsLastYear, -4)); $this->repository->avgCommitsPerWeek = count($commitsLastYear) > 0 ? floor(array_sum($commitsLastYear) / count($commitsLastYear)) : 0; // repository contributors $paginator = new ResultPager($this->client); $contributors = $paginator->fetchAll($this->client->api('repo'), 'contributors', [$this->repository->username, $this->repository->repository, true]); $this->repository->contributorsCount = count($contributors); // user data $user = $this->client->api('user')->show($this->repository->username); $this->repository->userPublicRepos = $user['public_repos']; return $this; }
/** * @param Client $githubClient * @return GithubRepository */ public function setHttpClient(Client $githubClient) { $this->githubClient = $githubClient; // see https://developer.github.com/changes/2015-04-17-preview-repository-redirects/ $this->githubClient->getHttpClient()->setHeaders(array('Accept' => 'application/vnd.github.quicksilver-preview+json')); return $this; }
public function updateVersionsHistory(Bundle $bundle) { // no composer file if (null === ($composerName = $bundle->getComposerName())) { return false; } // query packagist json $packagistArray = $this->github->getHttpClient()->get($composerName, array(), array('url' => 'http://packagist.org/packages/:path.json')); // if json not encoded if (!is_array($packagistArray) || !isset($packagistArray['package'])) { return false; } $versionsHistory = array(); $versionsArray = $packagistArray['package']['versions']; foreach ($versionsArray as $version => $value) { // Skip `dev` packages, add only `dev-master` if (0 === strpos($version, 'dev-') && 'dev-master' != $version) { continue; } foreach (array('symfony/framework-bundle', 'symfony/symfony') as $requirement) { if (isset($value['require'][$requirement])) { $versionsHistory['symfony'][$version] = $value['require'][$requirement]; // array('master' => '>=2.0,<2.2-dev') } } // store all bundle dependencies $versionsHistory['dependencies'][$version] = array('name' => $value['name'], 'extra' => isset($value['extra']) ? $value['require-dev'] : '', 'require' => $value['require'], 'require-dev' => isset($value['require-dev']) ? $value['require-dev'] : '', 'suggest' => isset($value['suggest']) ? $value['suggest'] : ''); } if (!empty($versionsHistory)) { $bundle->setVersionsHistory($versionsHistory); } return true; }
/** * Temporary workaround of the GitHub client bug * * @param string $sha * @return string */ protected function getContents($sha) { $path = 'repos/' . rawurlencode($this->user) . '/' . rawurlencode($this->repo) . '/git/blobs/' . rawurlencode($sha); $response = $this->client->getHttpClient()->get($path); $contents = $response->getBody(true); return $contents; }
/** * {@inheritdoc} */ public function register(Application $app) { $app['github'] = $app->share(function () { $client = new Client(new CachedHttpClient(['cache_dir' => __DIR__ . '/../../../app/cache/github-api-cache'])); return new GithubAdapter($client->getHttpClient()); }); }
/** * {@inheritdoc} */ protected function get($key) { if ($this->has($key)) { $result = $this->client->getHttpClient()->get($this->pagination[$key]); $this->postFetch(); return ResponseMediator::getContent($result); } }
/** * Update webhooks for repo * * @param $repo * @param $secret */ private function updateRemoteStatus($repo, $secret) { foreach (['issues', 'issue_comment'] as $event) { $action = $repo->isUsed() ? 'subscribe' : 'unsubscribe'; $topic = 'https://github.com/' . $repo->getFullname() . '/events/' . $event; $this->client->getHttpClient()->post('/hub', ['hub.mode' => $action, 'hub.topic' => $topic, 'hub.callback' => UrlHelper::getHost() . '/github/fromissue', 'hub.secret' => $secret]); } }
/** * Debug HTTP interactions * * @param Client $client * @param OutputInterface $output */ protected function logHttp(Client $client, OutputInterface $output) { $guzzle = $client->getHttpClient(); if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) { $logger = function ($message) use($output) { $finfo = new \finfo(FILEINFO_MIME); $msg = substr($finfo->buffer($message), 0, 4) == 'text' ? $message : '(binary string)'; $output->writeln('<info>Guzzle</info> ' . $msg); }; $logAdapter = new ClosureLogAdapter($logger); $logPlugin = new LogPlugin($logAdapter, MessageFormatter::DEBUG_FORMAT); $guzzle->addSubscriber($logPlugin); } }
/** * @return Client */ protected function buildGitHubClient() { $httpClient = new HttpClient(['base_url' => $this->config['base_url']]); $client = new Client($httpClient); if (false !== getenv('GITHUB_DEBUG')) { $logPlugin = LogPlugin::getDebugPlugin(); $httpClient = $client->getHttpClient(); $httpClient->addSubscriber($logPlugin); } $client->setOption('base_url', $this->config['base_url']); $this->url = rtrim($this->config['base_url'], '/'); $this->domain = rtrim($this->config['repo_domain_url'], '/'); return $client; }
public function it_returns_Issue_objects_on_getIssues(Client $client, Issue $api, HttpClient $http, Response $response) { $client->issue()->willReturn($api); $client->getHttpClient()->willReturn($http); $api->getPerPage()->willReturn(5); $api->setPerPage(Argument::any())->willReturn(); $http->getLastResponse()->willReturn($response); $response->getHeader('Link')->willReturn(null); $api->all('foo', 'bar', ['state' => 'open'])->willReturn([['number' => 1], ['number' => 5]]); $result = $this->getIssues(); $result->shouldBeArray(); $result->shouldHaveCount(2); $result[0]->shouldHaveType('Rs\\Issues\\Github\\GithubIssue'); $result[0]->getId()->shouldBe(1); $result[1]->shouldHaveType('Rs\\Issues\\Github\\GithubIssue'); $result[1]->getId()->shouldBe(5); }
public function testInstanciateWithHttpClient() { $httpClient = $this->getHttpClientMock(); $client = new Client($httpClient); $this->assertEquals($httpClient, $client->getHttpClient()); }
/** * @test */ public function shouldSetHeadersLaizly() { $client = new Client(); $client->setHeaders(array('header1', 'header2')); $this->assertInstanceOf('Github\\HttpClient\\HttpClientInterface', $client->getHttpClient()); }
/** * @param $gistId * @param $comment * @return array */ public function postGistComment($gistId, $comment) { $this->github->authenticate(Auth::user()->token, GitHubClient::AUTH_HTTP_TOKEN); $response = $this->github->getHttpClient()->post("gists/{$gistId}/comments", json_encode(['body' => $comment])); return ResponseMediator::getContent($response); }
private function getRawActivities($limit = 5) { $response = $this->client->getHttpClient()->get("users/{$this->user}/events"); $activities = ResponseMediator::getContent($response); return array_slice($activities, 0, $limit); }
/** * @test */ public function shouldPassHttpClientInterfaceToConstructor() { $client = new Client($this->getHttpClientMock()); $this->assertInstanceOf('Github\\HttpClient\\HttpClientInterface', $client->getHttpClient()); }
/** * @param $gistId * @return array */ public function getGistComments($gistId) { $response = $this->github->getHttpClient()->get("gists/{$gistId}/comments"); return ResponseMediator::getContent($response); }
/** * {@inheritDoc} */ protected function delete($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders); return $response->getContent(); }
/** * Send a DELETE request with JSON-encoded parameters. * * @param string $path Request path. * @param array $parameters POST parameters to be JSON encoded. * @param array $requestHeaders Request headers. */ protected function delete($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->delete($path, $this->createJsonBody($parameters), $requestHeaders); return ResponseMediator::getContent($response); }
/** * Parses markdown via GitHub. * * @param $markdown * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ public function parseMarkdown($markdown) { $body = json_encode(['text' => $markdown]); $response = $this->client->getHttpClient()->post('markdown', $body); return ResponseMediator::getContent($response); }
/** * Get the Api rate limit. * * @return array */ public function getApiRateLimit() { return ResponseMediator::getContent($this->github->getHttpClient()->get('rate_limit')); }