1
0
Fork 0

Merge pull request #2035 from xrstf/bitbucket-api-fix

fixed Bitbucket's broken API
pull/2019/merge
Jordi Boggiano 2013-06-25 06:58:01 -07:00
commit 20dda687c5
1 changed files with 14 additions and 8 deletions

View File

@ -44,7 +44,7 @@ class HgBitbucketDriver extends VcsDriver
public function getRootIdentifier() public function getRootIdentifier()
{ {
if (null === $this->rootIdentifier) { 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); $repoData = JsonFile::parseJson($this->getContents($resource), $resource);
if (array() === $repoData) { 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'); 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) public function getComposerInformation($identifier)
{ {
if (!isset($this->infoCache[$identifier])) { if (!isset($this->infoCache[$identifier])) {
$resource = $this->getScheme() . '://bitbucket.org/'.$this->owner.'/'.$this->repository.'/raw/'.$identifier.'/composer.json'; $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/src/'.$identifier.'/composer.json';
$composer = $this->getContents($resource); $repoData = JsonFile::parseJson($this->getContents($resource), $resource);
if (!$composer) {
// 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; return;
} }
$composer = JsonFile::parseJson($composer, $resource); $composer = JsonFile::parseJson($repoData['data'], $resource);
if (!isset($composer['time'])) { 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); $changeset = JsonFile::parseJson($this->getContents($resource), $resource);
$composer['time'] = $changeset['timestamp']; $composer['time'] = $changeset['timestamp'];
} }
@ -115,7 +121,7 @@ class HgBitbucketDriver extends VcsDriver
public function getTags() public function getTags()
{ {
if (null === $this->tags) { 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); $tagsData = JsonFile::parseJson($this->getContents($resource), $resource);
$this->tags = array(); $this->tags = array();
foreach ($tagsData as $tag => $data) { foreach ($tagsData as $tag => $data) {
@ -132,7 +138,7 @@ class HgBitbucketDriver extends VcsDriver
public function getBranches() public function getBranches()
{ {
if (null === $this->branches) { 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); $branchData = JsonFile::parseJson($this->getContents($resource), $resource);
$this->branches = array(); $this->branches = array();
foreach ($branchData as $branch => $data) { foreach ($branchData as $branch => $data) {