diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 3e8b70edd..aea5a253f 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -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 { $content = $this->getContents($resource); @@ -248,7 +248,7 @@ class GitLabDriver extends VcsDriver */ 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 $resource = $this->getApiUrl(); $this->project = JsonFile::parseJson($this->getContents($resource, true), $resource); - $this->isPrivate = !$this->project['public']; + $this->isPrivate = $this->project['visibility'] !== 'public'; } protected function attemptCloneFallback() diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index 590ba99ef..c663f929d 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -58,9 +58,9 @@ class GitLabDriverTest extends TestCase public function getInitializeUrls() { return array( - array('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v3/projects/mygroup%2Fmyproject'), - array('http://gitlab.com/mygroup/myproject', 'http://gitlab.com/api/v3/projects/mygroup%2Fmyproject'), - array('git@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/v4/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, "default_branch": "mymaster", - "public": false, + "visibility": "private", "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", @@ -113,7 +113,7 @@ JSON; { "id": 17, "default_branch": "mymaster", - "public": true, + "visibility": "public", "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", @@ -144,12 +144,12 @@ JSON; 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'; $expected = array( '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, 'shasum' => '', ); @@ -159,7 +159,7 @@ JSON; 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'; $expected = array( @@ -173,7 +173,7 @@ JSON; 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'; $expected = array( @@ -187,9 +187,9 @@ JSON; 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 $tagData = <<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 $branchData = <<