diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index f2813db54..45cdac717 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -308,7 +308,12 @@ class GitLabDriver extends VcsDriver // we need to fetch the default branch from the api $resource = $this->getApiUrl(); $this->project = JsonFile::parseJson($this->getContents($resource, true), $resource); - $this->isPrivate = $this->project['visibility'] !== 'public'; + if (isset($this->project['visibility'])) { + $this->isPrivate = $this->project['visibility'] !== 'public'; + } else { + // client is not authendicated, therefore repository has to be public + $this->isPrivate = false; + } } protected function attemptCloneFallback() diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index 1564412d8..25634138f 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -142,6 +142,44 @@ JSON; return $driver; } + /** + * @dataProvider getInitializeUrls + */ + public function testInitializePublicProjectAsAnonymous($url, $apiUrl) + { + // @link http://doc.gitlab.com/ce/api/projects.html#get-single-project + $projectData = <<remoteFilesystem + ->getContents('gitlab.com', $apiUrl, false, array()) + ->willReturn($projectData) + ->shouldBeCalledTimes(1) + ; + + $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->process->reveal(), $this->remoteFilesystem->reveal()); + $driver->initialize(); + + $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL'); + $this->assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab'); + $this->assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default'); + $this->assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl()); + + return $driver; + } + public function testGetDist() { $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');