Update GitLab API usage to v4, fixes #6453

main
Jordi Boggiano 7 years ago
parent ec2722f879
commit 6832eacb01

@ -126,7 +126,7 @@ class GitLabDriver extends VcsDriver
} }
} }
$resource = $this->getApiUrl().'/repository/blobs/'.$identifier.'?filepath=' . $file; $resource = $this->getApiUrl().'/repository/files/'.$this->urlEncodeAll($file).'/raw?ref='.$identifier;
try { try {
$content = $this->getContents($resource); $content = $this->getContents($resource);
@ -248,7 +248,7 @@ class GitLabDriver extends VcsDriver
*/ */
public function getApiUrl() public function getApiUrl()
{ {
return $this->scheme.'://'.$this->originUrl.'/api/v3/projects/'.$this->urlEncodeAll($this->namespace).'%2F'.$this->urlEncodeAll($this->repository); return $this->scheme.'://'.$this->originUrl.'/api/v4/projects/'.$this->urlEncodeAll($this->namespace).'%2F'.$this->urlEncodeAll($this->repository);
} }
/** /**
@ -300,7 +300,7 @@ 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);
$this->isPrivate = !$this->project['public']; $this->isPrivate = $this->project['visibility'] !== 'public';
} }
protected function attemptCloneFallback() protected function attemptCloneFallback()

@ -58,9 +58,9 @@ class GitLabDriverTest extends TestCase
public function getInitializeUrls() public function getInitializeUrls()
{ {
return array( return array(
array('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject'), array('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'),
array('http://gitlab.com/mygroup/myproject', 'http://gitlab.com/api/v3/projects/mygroup%2Fmyproject'), array('http://gitlab.com/mygroup/myproject', 'http://gitlab.com/api/v4/projects/mygroup%2Fmyproject'),
array('git@gitlab.com:mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject'), array('git@gitlab.com:mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'),
); );
} }
@ -74,7 +74,7 @@ class GitLabDriverTest extends TestCase
{ {
"id": 17, "id": 17,
"default_branch": "mymaster", "default_branch": "mymaster",
"public": false, "visibility": "private",
"http_url_to_repo": "https://gitlab.com/mygroup/myproject.git", "http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
"ssh_url_to_repo": "git@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", "last_activity_at": "2014-12-01T09:17:51.000+01:00",
@ -113,7 +113,7 @@ JSON;
{ {
"id": 17, "id": 17,
"default_branch": "mymaster", "default_branch": "mymaster",
"public": true, "visibility": "public",
"http_url_to_repo": "https://gitlab.com/mygroup/myproject.git", "http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
"ssh_url_to_repo": "git@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", "last_activity_at": "2014-12-01T09:17:51.000+01:00",
@ -144,12 +144,12 @@ JSON;
public function testGetDist() public function testGetDist()
{ {
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject'); $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
$reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363'; $reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
$expected = array( $expected = array(
'type' => 'zip', 'type' => 'zip',
'url' => 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject/repository/archive.zip?sha='.$reference, 'url' => 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/archive.zip?sha='.$reference,
'reference' => $reference, 'reference' => $reference,
'shasum' => '', 'shasum' => '',
); );
@ -159,7 +159,7 @@ JSON;
public function testGetSource() public function testGetSource()
{ {
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject'); $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
$reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363'; $reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
$expected = array( $expected = array(
@ -173,7 +173,7 @@ JSON;
public function testGetSource_GivenPublicProject() public function testGetSource_GivenPublicProject()
{ {
$driver = $this->testInitializePublicProject('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject', true); $driver = $this->testInitializePublicProject('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject', true);
$reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363'; $reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
$expected = array( $expected = array(
@ -187,9 +187,9 @@ JSON;
public function testGetTags() public function testGetTags()
{ {
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject'); $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
$apiUrl = 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject/repository/tags'; $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags';
// @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-tags // @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-tags
$tagData = <<<JSON $tagData = <<<JSON
@ -229,9 +229,9 @@ JSON;
public function testGetBranches() public function testGetBranches()
{ {
$driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject'); $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
$apiUrl = 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject/repository/branches'; $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/branches';
// @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-branches // @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-branches
$branchData = <<<JSON $branchData = <<<JSON
@ -300,13 +300,13 @@ JSON;
public function testGitlabSubDirectory() public function testGitlabSubDirectory()
{ {
$url = 'https://mycompany.com/gitlab/mygroup/my-pro.ject'; $url = 'https://mycompany.com/gitlab/mygroup/my-pro.ject';
$apiUrl = 'https://mycompany.com/gitlab/api/v3/projects/mygroup%2Fmy-pro%2Eject'; $apiUrl = 'https://mycompany.com/gitlab/api/v4/projects/mygroup%2Fmy-pro%2Eject';
$projectData = <<<JSON $projectData = <<<JSON
{ {
"id": 17, "id": 17,
"default_branch": "mymaster", "default_branch": "mymaster",
"public": false, "visibility": "private",
"http_url_to_repo": "https://gitlab.com/gitlab/mygroup/my-pro.ject", "http_url_to_repo": "https://gitlab.com/gitlab/mygroup/my-pro.ject",
"ssh_url_to_repo": "git@gitlab.com:mygroup/my-pro.ject.git", "ssh_url_to_repo": "git@gitlab.com:mygroup/my-pro.ject.git",
"last_activity_at": "2014-12-01T09:17:51.000+01:00", "last_activity_at": "2014-12-01T09:17:51.000+01:00",
@ -333,13 +333,13 @@ JSON;
public function testGitlabSubGroup() public function testGitlabSubGroup()
{ {
$url = 'https://gitlab.com/mygroup/mysubgroup/myproject'; $url = 'https://gitlab.com/mygroup/mysubgroup/myproject';
$apiUrl = 'https://gitlab.com/api/v3/projects/mygroup%2Fmysubgroup%2Fmyproject'; $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmysubgroup%2Fmyproject';
$projectData = <<<JSON $projectData = <<<JSON
{ {
"id": 17, "id": 17,
"default_branch": "mymaster", "default_branch": "mymaster",
"public": false, "visibility": "private",
"http_url_to_repo": "https://gitlab.com/mygroup/mysubgroup/my-pro.ject", "http_url_to_repo": "https://gitlab.com/mygroup/mysubgroup/my-pro.ject",
"ssh_url_to_repo": "git@gitlab.com:mygroup/mysubgroup/my-pro.ject.git", "ssh_url_to_repo": "git@gitlab.com:mygroup/mysubgroup/my-pro.ject.git",
"last_activity_at": "2014-12-01T09:17:51.000+01:00", "last_activity_at": "2014-12-01T09:17:51.000+01:00",
@ -366,13 +366,13 @@ JSON;
public function testGitlabSubDirectorySubGroup() public function testGitlabSubDirectorySubGroup()
{ {
$url = 'https://mycompany.com/gitlab/mygroup/mysubgroup/myproject'; $url = 'https://mycompany.com/gitlab/mygroup/mysubgroup/myproject';
$apiUrl = 'https://mycompany.com/gitlab/api/v3/projects/mygroup%2Fmysubgroup%2Fmyproject'; $apiUrl = 'https://mycompany.com/gitlab/api/v4/projects/mygroup%2Fmysubgroup%2Fmyproject';
$projectData = <<<JSON $projectData = <<<JSON
{ {
"id": 17, "id": 17,
"default_branch": "mymaster", "default_branch": "mymaster",
"public": false, "visibility": "private",
"http_url_to_repo": "https://mycompany.com/gitlab/mygroup/mysubgroup/my-pro.ject", "http_url_to_repo": "https://mycompany.com/gitlab/mygroup/mysubgroup/my-pro.ject",
"ssh_url_to_repo": "git@mycompany.com:mygroup/mysubgroup/my-pro.ject.git", "ssh_url_to_repo": "git@mycompany.com:mygroup/mysubgroup/my-pro.ject.git",
"last_activity_at": "2014-12-01T09:17:51.000+01:00", "last_activity_at": "2014-12-01T09:17:51.000+01:00",
@ -407,7 +407,7 @@ JSON;
{ {
"id": 17, "id": 17,
"default_branch": "mymaster", "default_branch": "mymaster",
"public": false, "visibility": "private",
"http_url_to_repo": "https://gitlab.mycompany.local/mygroup/myproject", "http_url_to_repo": "https://gitlab.mycompany.local/mygroup/myproject",
"ssh_url_to_repo": "git@gitlab.mycompany.local:mygroup/myproject.git", "ssh_url_to_repo": "git@gitlab.mycompany.local:mygroup/myproject.git",
"last_activity_at": "2014-12-01T09:17:51.000+01:00", "last_activity_at": "2014-12-01T09:17:51.000+01:00",

Loading…
Cancel
Save