Update repo url from github and handle trailing slashes, refs composer/packagist#354 refs composer/packagist#423
parent
ea6917c87a
commit
d5294ef91b
|
@ -46,7 +46,7 @@ class GitHubDriver extends VcsDriver
|
||||||
*/
|
*/
|
||||||
public function initialize()
|
public function initialize()
|
||||||
{
|
{
|
||||||
preg_match('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git)?$#', $this->url, $match);
|
preg_match('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git|/)?$#', $this->url, $match);
|
||||||
$this->owner = $match[3];
|
$this->owner = $match[3];
|
||||||
$this->repository = $match[4];
|
$this->repository = $match[4];
|
||||||
$this->originUrl = !empty($match[1]) ? $match[1] : $match[2];
|
$this->originUrl = !empty($match[1]) ? $match[1] : $match[2];
|
||||||
|
@ -61,6 +61,11 @@ class GitHubDriver extends VcsDriver
|
||||||
$this->fetchRootIdentifier();
|
$this->fetchRootIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRepositoryUrl()
|
||||||
|
{
|
||||||
|
return 'https://'.$this->originUrl.'/'.$this->owner.'/'.$this->repository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -250,7 +255,7 @@ class GitHubDriver extends VcsDriver
|
||||||
*/
|
*/
|
||||||
public static function supports(IOInterface $io, Config $config, $url, $deep = false)
|
public static function supports(IOInterface $io, Config $config, $url, $deep = false)
|
||||||
{
|
{
|
||||||
if (!preg_match('#^((?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git)?$#', $url, $matches)) {
|
if (!preg_match('#^((?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git|/)?$#', $url, $matches)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,6 +406,9 @@ class GitHubDriver extends VcsDriver
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->owner = $repoData['owner']['login'];
|
||||||
|
$this->repository = $repoData['name'];
|
||||||
|
|
||||||
$this->isPrivate = !empty($repoData['private']);
|
$this->isPrivate = !empty($repoData['private']);
|
||||||
if (isset($repoData['default_branch'])) {
|
if (isset($repoData['default_branch'])) {
|
||||||
$this->rootIdentifier = $repoData['default_branch'];
|
$this->rootIdentifier = $repoData['default_branch'];
|
||||||
|
|
|
@ -91,7 +91,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
$remoteFilesystem->expects($this->at(3))
|
$remoteFilesystem->expects($this->at(3))
|
||||||
->method('getContents')
|
->method('getContents')
|
||||||
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
||||||
->will($this->returnValue('{"master_branch": "test_master", "private": true}'));
|
->will($this->returnValue('{"master_branch": "test_master", "private": true, "owner": {"login": "composer"}, "name": "packagist"}'));
|
||||||
|
|
||||||
$configSource = $this->getMock('Composer\Config\ConfigSourceInterface');
|
$configSource = $this->getMock('Composer\Config\ConfigSourceInterface');
|
||||||
$authConfigSource = $this->getMock('Composer\Config\ConfigSourceInterface');
|
$authConfigSource = $this->getMock('Composer\Config\ConfigSourceInterface');
|
||||||
|
@ -138,7 +138,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
$remoteFilesystem->expects($this->at(0))
|
$remoteFilesystem->expects($this->at(0))
|
||||||
->method('getContents')
|
->method('getContents')
|
||||||
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
||||||
->will($this->returnValue('{"master_branch": "test_master"}'));
|
->will($this->returnValue('{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist"}'));
|
||||||
|
|
||||||
$repoConfig = array(
|
$repoConfig = array(
|
||||||
'url' => $repoUrl,
|
'url' => $repoUrl,
|
||||||
|
@ -181,7 +181,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
$remoteFilesystem->expects($this->at(0))
|
$remoteFilesystem->expects($this->at(0))
|
||||||
->method('getContents')
|
->method('getContents')
|
||||||
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
|
||||||
->will($this->returnValue('{"master_branch": "test_master"}'));
|
->will($this->returnValue('{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist"}'));
|
||||||
|
|
||||||
$remoteFilesystem->expects($this->at(1))
|
$remoteFilesystem->expects($this->at(1))
|
||||||
->method('getContents')
|
->method('getContents')
|
||||||
|
|
Loading…
Reference in New Issue