From 7ae4ed1ec88c8b76731a8933344b6536ba7f03f3 Mon Sep 17 00:00:00 2001 From: Stefan Grootscholten Date: Wed, 28 Dec 2016 22:43:24 +0100 Subject: [PATCH] Improve fetching single files via bitbucket API. The former implementation used the 'src' endpoint which returned some meta data as well. This has been replaced with the 'raw' endpoint which does not return the meta data and does not need an extra JSON decode step. --- src/Composer/Repository/Vcs/BitbucketDriver.php | 8 ++------ .../Test/Repository/Vcs/GitBitbucketDriverTest.php | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Composer/Repository/Vcs/BitbucketDriver.php b/src/Composer/Repository/Vcs/BitbucketDriver.php index 51eee5358..8a2e78a98 100644 --- a/src/Composer/Repository/Vcs/BitbucketDriver.php +++ b/src/Composer/Repository/Vcs/BitbucketDriver.php @@ -166,18 +166,14 @@ abstract class BitbucketDriver extends VcsDriver } $resource = sprintf( - 'https://api.bitbucket.org/1.0/repositories/%s/%s/src/%s/%s', + 'https://api.bitbucket.org/1.0/repositories/%s/%s/raw/%s/%s', $this->owner, $this->repository, $identifier, $file ); - $fileData = JsonFile::parseJson($this->getContents($resource), $resource); - if (!is_array($fileData) || ! array_key_exists('data', $fileData)) { - return null; - } - return $fileData['data']; + return $this->getContents($resource); } /** diff --git a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php index e744ce241..30ec81130 100644 --- a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php @@ -128,7 +128,7 @@ class GitBitbucketDriverTest extends TestCase ), array( $this->originUrl, - 'https://api.bitbucket.org/1.0/repositories/user/repo/src/master/composer.json', + 'https://api.bitbucket.org/1.0/repositories/user/repo/raw/master/composer.json', false ), array( @@ -142,7 +142,7 @@ class GitBitbucketDriverTest extends TestCase '{"name": "master"}', '{"values":[{"name":"1.0.1","target":{"hash":"9b78a3932143497c519e49b8241083838c8ff8a1"}},{"name":"1.0.0","target":{"hash":"d3393d514318a9267d2f8ebbf463a9aaa389f8eb"}}]}', '{"values":[{"name":"master","target":{"hash":"937992d19d72b5116c3e8c4a04f960e5fa270b22"}}]}', - '{"node": "937992d19d72", "path": "composer.json", "data": "{\n \"name\": \"user/repo\",\n \"description\": \"test repo\",\n \"license\": \"GPL\",\n \"authors\": [\n {\n \"name\": \"Name\",\n \"email\": \"local@domain.tld\"\n }\n ],\n \"require\": {\n \"creator/package\": \"^1.0\"\n },\n \"require-dev\": {\n \"phpunit/phpunit\": \"~4.8\"\n }\n}\n", "size": 269}', + '{"name": "user/repo","description": "test repo","license": "GPL","authors": [{"name": "Name","email": "local@domain.tld"}],"require": {"creator/package": "^1.0"},"require-dev": {"phpunit/phpunit": "~4.8"}}', '{"node": "937992d19d72", "files": [{"type": "modified", "file": "path/to/file"}], "raw_author": "User ", "utctimestamp": "2016-05-17 11:19:52+00:00", "author": "user", "timestamp": "2016-05-17 13:19:52", "raw_node": "937992d19d72b5116c3e8c4a04f960e5fa270b22", "parents": ["71e195a33361"], "branch": "master", "message": "Commit message\n", "revision": null, "size": -1}' );