From 6406e0d3b7c7fb0a0e7e5f29ebd302fdcbe02ac0 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 25 Jun 2013 02:06:26 +0200 Subject: [PATCH] fixed Bitbucket's broken API --- .../Repository/Vcs/HgBitbucketDriver.php | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Composer/Repository/Vcs/HgBitbucketDriver.php b/src/Composer/Repository/Vcs/HgBitbucketDriver.php index 37a8f0d90..cd2342d23 100644 --- a/src/Composer/Repository/Vcs/HgBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/HgBitbucketDriver.php @@ -44,7 +44,7 @@ class HgBitbucketDriver extends VcsDriver public function getRootIdentifier() { if (null === $this->rootIdentifier) { - $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags'; + $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags'; $repoData = JsonFile::parseJson($this->getContents($resource), $resource); if (array() === $repoData) { throw new \RuntimeException('This does not appear to be a mercurial repository, use '.$this->url.'.git if this is a git bitbucket repository'); @@ -90,16 +90,22 @@ class HgBitbucketDriver extends VcsDriver public function getComposerInformation($identifier) { if (!isset($this->infoCache[$identifier])) { - $resource = $this->getScheme() . '://bitbucket.org/'.$this->owner.'/'.$this->repository.'/raw/'.$identifier.'/composer.json'; - $composer = $this->getContents($resource); - if (!$composer) { + $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/src/'.$identifier.'/composer.json'; + $repoData = JsonFile::parseJson($this->getContents($resource), $resource); + + // Bitbucket does not send different response codes for found and + // not found files, so we have to check the response structure. + // found: {node: ..., data: ..., size: ..., ...} + // not found: {node: ..., files: [...], directories: [...], ...} + + if (!array_key_exists('data', $repoData)) { return; } - $composer = JsonFile::parseJson($composer, $resource); + $composer = JsonFile::parseJson($repoData['data'], $resource); if (!isset($composer['time'])) { - $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/changesets/'.$identifier; + $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/changesets/'.$identifier; $changeset = JsonFile::parseJson($this->getContents($resource), $resource); $composer['time'] = $changeset['timestamp']; } @@ -115,7 +121,7 @@ class HgBitbucketDriver extends VcsDriver public function getTags() { if (null === $this->tags) { - $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags'; + $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags'; $tagsData = JsonFile::parseJson($this->getContents($resource), $resource); $this->tags = array(); foreach ($tagsData as $tag => $data) { @@ -132,7 +138,7 @@ class HgBitbucketDriver extends VcsDriver public function getBranches() { if (null === $this->branches) { - $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/branches'; + $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/branches'; $branchData = JsonFile::parseJson($this->getContents($resource), $resource); $this->branches = array(); foreach ($branchData as $branch => $data) {