From 259a25344dcb694b1f58b92b36ffe30690474dc4 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 27 Feb 2013 14:02:57 +0100 Subject: [PATCH] Use the api to get file contents instead of raw.github.com raw.github does not like the access_token query param --- src/Composer/Repository/Vcs/GitHubDriver.php | 7 +++++-- tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 2af0234fb..f7cb948a8 100755 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -128,8 +128,11 @@ class GitHubDriver extends VcsDriver if (!isset($this->infoCache[$identifier])) { try { - $resource = 'https://raw.github.com/'.$this->owner.'/'.$this->repository.'/'.$identifier.'/composer.json'; - $composer = $this->getContents($resource); + $resource = 'https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/contents/composer.json?ref='.urlencode($identifier); + $composer = JsonFile::parseJson($this->getContents($resource)); + if (empty($composer['content']) || $composer['encoding'] !== 'base64' || !($composer = base64_decode($composer['content']))) { + throw new \RuntimeException('Could not retrieve composer.json from '.$resource); + } } catch (TransportException $e) { if (404 !== $e->getCode()) { throw $e; diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 4ebc863de..1f1bb963f 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -198,8 +198,8 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase $remoteFilesystem->expects($this->at(1)) ->method('getContents') - ->with($this->equalTo('github.com'), $this->equalTo('https://raw.github.com/composer/packagist/feature/3.2-foo/composer.json'), $this->equalTo(false)) - ->will($this->returnValue('{"support": {"source": "'.$repoUrl.'" }}')); + ->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/repos/composer/packagist/contents/composer.json?ref=feature%2F3.2-foo'), $this->equalTo(false)) + ->will($this->returnValue('{"encoding":"base64","content":"'.base64_encode('{"support": {"source": "'.$repoUrl.'" }}').'"}')); $remoteFilesystem->expects($this->at(2)) ->method('getContents')