1
0
Fork 0

Update code to use new github archive URLs

pull/1288/head
Jordi Boggiano 2012-11-04 14:01:22 +01:00
parent 0878c6deab
commit 1682532b80
4 changed files with 32 additions and 9 deletions

View File

@ -87,14 +87,21 @@ abstract class ArchiveDownloader extends FileDownloader
*/
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');
}

View File

@ -108,7 +108,7 @@ class GitHubDriver extends VcsDriver
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' => '');
}

View File

@ -43,7 +43,23 @@ class ArchiveDownloaderTest extends \PHPUnit_Framework_TestCase
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);
}
}
}

View File

@ -97,7 +97,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
$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 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
$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 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
$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 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
$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 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
$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 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
$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);