1
0
Fork 0

fix gitlab not telling visibilty if user is not logged in

pull/6651/merge
Mikk Tendermann 2017-08-31 20:14:41 +03:00 committed by Jordi Boggiano
parent 37addea447
commit 2a89d37651
2 changed files with 44 additions and 1 deletions

View File

@ -308,7 +308,12 @@ class GitLabDriver extends VcsDriver
// we need to fetch the default branch from the api // we need to fetch the default branch from the api
$resource = $this->getApiUrl(); $resource = $this->getApiUrl();
$this->project = JsonFile::parseJson($this->getContents($resource, true), $resource); $this->project = JsonFile::parseJson($this->getContents($resource, true), $resource);
if (isset($this->project['visibility'])) {
$this->isPrivate = $this->project['visibility'] !== 'public'; $this->isPrivate = $this->project['visibility'] !== 'public';
} else {
// client is not authendicated, therefore repository has to be public
$this->isPrivate = false;
}
} }
protected function attemptCloneFallback() protected function attemptCloneFallback()

View File

@ -142,6 +142,44 @@ JSON;
return $driver; return $driver;
} }
/**
* @dataProvider getInitializeUrls
*/
public function testInitializePublicProjectAsAnonymous($url, $apiUrl)
{
// @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
$projectData = <<<JSON
{
"id": 17,
"default_branch": "mymaster",
"http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
"ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
"last_activity_at": "2014-12-01T09:17:51.000+01:00",
"name": "My Project",
"name_with_namespace": "My Group / My Project",
"path": "myproject",
"path_with_namespace": "mygroup/myproject",
"web_url": "https://gitlab.com/mygroup/myproject"
}
JSON;
$this->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() public function testGetDist()
{ {
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'); $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');