From 1682532b80b9a9fee1b70458f5dbac845561881e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 4 Nov 2012 14:01:22 +0100 Subject: [PATCH] Update code to use new github archive URLs --- src/Composer/Downloader/ArchiveDownloader.php | 9 ++++++++- src/Composer/Repository/Vcs/GitHubDriver.php | 2 +- .../Test/Downloader/ArchiveDownloaderTest.php | 18 +++++++++++++++++- .../Test/Repository/Vcs/GitHubDriverTest.php | 12 ++++++------ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index e86fec849387..fea972b30571 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -87,14 +87,21 @@ protected function getFileName(PackageInterface $package, $path) */ protected function processUrl(PackageInterface $package, $url) { + // support for legacy github archives if ($package->getDistReference() && preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) { $url = 'https://github.com/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference(); } + if ($package->getDistReference() && preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar\.gz)$}i', $url, $match)) { + $url = 'https://github.com/' . $match[1] . '/'. $match[2] . '/archive/' . $package->getDistReference() . '.' . $match[3]; + } + if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) { // bypass https for github if openssl is disabled if (preg_match('{^https?://github.com/([^/]+/[^/]+)/(zip|tar)ball/([^/]+)$}i', $url, $match)) { - $url = 'http://nodeload.github.com/'.$match[1].'/legacy.'.$match[2].'/'.$match[3]; + $url = 'http://nodeload.github.com/'.$match[1].'/'.$match[2].'/'.$match[3]; + } elseif (preg_match('{^https?://github.com/([^/]+/[^/]+)/archive/([^/]+)\.(zip|tar\.gz)$}i', $url, $match)) { + $url = 'http://nodeload.github.com/'.$match[1].'/'.$match[3].'/'.$match[2]; } else { throw new \RuntimeException('You must enable the openssl extension to download files via https'); } diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index fea55c462e73..da840673c329 100755 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -108,7 +108,7 @@ public function getDist($identifier) return $this->gitDriver->getDist($identifier); } $label = array_search($identifier, $this->getTags()) ?: $identifier; - $url = 'https://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$label; + $url = 'https://github.com/'.$this->owner.'/'.$this->repository.'/archive/'.$label.'.zip'; return array('type' => 'zip', 'url' => $url, 'reference' => $label, 'shasum' => ''); } diff --git a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php index 1d9de15089d6..74e76d85db88 100644 --- a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php @@ -43,7 +43,23 @@ public function testProcessUrl() if (extension_loaded('openssl')) { $this->assertEquals($expected, $url); } else { - $this->assertEquals('http://nodeload.github.com/composer/composer/legacy.zip/master', $url); + $this->assertEquals('http://nodeload.github.com/composer/composer/zip/master', $url); + } + } + + public function testProcessUrl2() + { + $downloader = $this->getMockForAbstractClass('Composer\Downloader\ArchiveDownloader', array($this->getMock('Composer\IO\IOInterface'), $this->getMock('Composer\Config'))); + $method = new \ReflectionMethod($downloader, 'processUrl'); + $method->setAccessible(true); + + $expected = 'https://github.com/composer/composer/archive/master.tar.gz'; + $url = $method->invoke($downloader, $this->getMock('Composer\Package\PackageInterface'), $expected); + + if (extension_loaded('openssl')) { + $this->assertEquals($expected, $url); + } else { + $this->assertEquals('http://nodeload.github.com/composer/composer/tar.gz/master', $url); } } } diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index ccde42a00145..1598a18267ca 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -97,7 +97,7 @@ public function testPrivateRepository() $dist = $gitHubDriver->getDist($identifier); $this->assertEquals('zip', $dist['type']); - $this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']); + $this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']); $this->assertEquals('v0.0.0', $dist['reference']); $source = $gitHubDriver->getSource($identifier); @@ -107,7 +107,7 @@ public function testPrivateRepository() $dist = $gitHubDriver->getDist($sha); $this->assertEquals('zip', $dist['type']); - $this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']); + $this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']); $this->assertEquals('v0.0.0', $dist['reference']); $source = $gitHubDriver->getSource($sha); @@ -149,7 +149,7 @@ public function testPublicRepository() $dist = $gitHubDriver->getDist($identifier); $this->assertEquals('zip', $dist['type']); - $this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']); + $this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']); $this->assertEquals($identifier, $dist['reference']); $source = $gitHubDriver->getSource($identifier); @@ -159,7 +159,7 @@ public function testPublicRepository() $dist = $gitHubDriver->getDist($sha); $this->assertEquals('zip', $dist['type']); - $this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']); + $this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']); $this->assertEquals($identifier, $dist['reference']); $source = $gitHubDriver->getSource($sha); @@ -211,7 +211,7 @@ public function testPublicRepository2() $dist = $gitHubDriver->getDist($identifier); $this->assertEquals('zip', $dist['type']); - $this->assertEquals('https://github.com/composer/packagist/zipball/feature/3.2-foo', $dist['url']); + $this->assertEquals('https://github.com/composer/packagist/archive/feature/3.2-foo.zip', $dist['url']); $this->assertEquals($identifier, $dist['reference']); $source = $gitHubDriver->getSource($identifier); @@ -221,7 +221,7 @@ public function testPublicRepository2() $dist = $gitHubDriver->getDist($sha); $this->assertEquals('zip', $dist['type']); - $this->assertEquals('https://github.com/composer/packagist/zipball/feature/3.2-foo', $dist['url']); + $this->assertEquals('https://github.com/composer/packagist/archive/feature/3.2-foo.zip', $dist['url']); $this->assertEquals($identifier, $dist['reference']); $source = $gitHubDriver->getSource($sha);