Browse Source

Update repo url from github and handle trailing slashes, refs composer/packagist#354 refs composer/packagist#423

Jordi Boggiano 10 years ago
parent
commit
d5294ef91b

+ 10 - 2
src/Composer/Repository/Vcs/GitHubDriver.php

@@ -46,7 +46,7 @@ class GitHubDriver extends VcsDriver
      */
     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->repository = $match[4];
         $this->originUrl = !empty($match[1]) ? $match[1] : $match[2];
@@ -61,6 +61,11 @@ class GitHubDriver extends VcsDriver
         $this->fetchRootIdentifier();
     }
 
+    public function getRepositoryUrl()
+    {
+        return 'https://'.$this->originUrl.'/'.$this->owner.'/'.$this->repository;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -250,7 +255,7 @@ class GitHubDriver extends VcsDriver
      */
     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;
         }
 
@@ -401,6 +406,9 @@ class GitHubDriver extends VcsDriver
             return;
         }
 
+        $this->owner = $repoData['owner']['login'];
+        $this->repository = $repoData['name'];
+
         $this->isPrivate = !empty($repoData['private']);
         if (isset($repoData['default_branch'])) {
             $this->rootIdentifier = $repoData['default_branch'];

+ 3 - 3
tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php

@@ -91,7 +91,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
         $remoteFilesystem->expects($this->at(3))
             ->method('getContents')
             ->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');
         $authConfigSource = $this->getMock('Composer\Config\ConfigSourceInterface');
@@ -138,7 +138,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
         $remoteFilesystem->expects($this->at(0))
             ->method('getContents')
             ->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(
             'url' => $repoUrl,
@@ -181,7 +181,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
         $remoteFilesystem->expects($this->at(0))
             ->method('getContents')
             ->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))
             ->method('getContents')