Add support section to composer data for bitbucket repositories.
parent
ccfd9018b8
commit
78fcb5a366
|
@ -34,6 +34,7 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface
|
||||||
protected $branches;
|
protected $branches;
|
||||||
protected $rootIdentifier;
|
protected $rootIdentifier;
|
||||||
protected $infoCache = array();
|
protected $infoCache = array();
|
||||||
|
private $hasIssues;
|
||||||
/**
|
/**
|
||||||
* @var GitDriver
|
* @var GitDriver
|
||||||
*/
|
*/
|
||||||
|
@ -63,6 +64,7 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface
|
||||||
if (null === $this->rootIdentifier) {
|
if (null === $this->rootIdentifier) {
|
||||||
$resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository;
|
$resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository;
|
||||||
$repoData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource, true), $resource);
|
$repoData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource, true), $resource);
|
||||||
|
$this->hasIssues = !empty($repoData['has_issues']);
|
||||||
$this->rootIdentifier = !empty($repoData['main_branch']) ? $repoData['main_branch'] : 'master';
|
$this->rootIdentifier = !empty($repoData['main_branch']) ? $repoData['main_branch'] : 'master';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +132,31 @@ class GitBitbucketDriver extends VcsDriver implements VcsDriverInterface
|
||||||
$changeset = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource);
|
$changeset = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource);
|
||||||
$composer['time'] = $changeset['timestamp'];
|
$composer['time'] = $changeset['timestamp'];
|
||||||
}
|
}
|
||||||
|
if (!isset($composer['support']['source'])) {
|
||||||
|
$label = array_search($identifier, $this->getTags()) ?: array_search($identifier, $this->getBranches()) ?: $identifier;
|
||||||
|
|
||||||
|
if (array_key_exists($label, $tags = $this->getTags())) {
|
||||||
|
$hash = $tags[$label];
|
||||||
|
} elseif (array_key_exists($label, $branches = $this->getBranches())) {
|
||||||
|
$hash = $branches[$label];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($hash)) {
|
||||||
|
$composer['support']['source'] = sprintf('https://%s/%s/%s/src', $this->originUrl, $this->owner, $this->repository);
|
||||||
|
} else {
|
||||||
|
$composer['support']['source'] = sprintf(
|
||||||
|
'https://%s/%s/%s/src/%s/?at=%s',
|
||||||
|
$this->originUrl,
|
||||||
|
$this->owner,
|
||||||
|
$this->repository,
|
||||||
|
$hash,
|
||||||
|
$label
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isset($composer['support']['issues']) && $this->hasIssues) {
|
||||||
|
$composer['support']['issues'] = sprintf('https://%s/%s/%s/issues', $this->originUrl, $this->owner, $this->repository);
|
||||||
|
}
|
||||||
|
|
||||||
if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
|
if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
|
||||||
$this->cache->write($identifier, json_encode($composer));
|
$this->cache->write($identifier, json_encode($composer));
|
||||||
|
|
|
@ -16,6 +16,9 @@ use Composer\Config;
|
||||||
use Composer\TestCase;
|
use Composer\TestCase;
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group bitbucket
|
||||||
|
*/
|
||||||
class GitBitbucketDriverTest extends TestCase
|
class GitBitbucketDriverTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @type \Composer\IO\IOInterface|\PHPUnit_Framework_MockObject_MockObject */
|
/** @type \Composer\IO\IOInterface|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
@ -124,11 +127,15 @@ class GitBitbucketDriverTest extends TestCase
|
||||||
->method('getContents')
|
->method('getContents')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
array('bitbucket.org', 'https://api.bitbucket.org/1.0/repositories/user/repo/src/master/composer.json', false),
|
array('bitbucket.org', 'https://api.bitbucket.org/1.0/repositories/user/repo/src/master/composer.json', false),
|
||||||
array('bitbucket.org', 'https://api.bitbucket.org/1.0/repositories/user/repo/changesets/master', false)
|
array('bitbucket.org', 'https://api.bitbucket.org/1.0/repositories/user/repo/changesets/master', false),
|
||||||
|
array('bitbucket.org', 'https://api.bitbucket.org/1.0/repositories/user/repo/tags', false),
|
||||||
|
array('bitbucket.org', 'https://api.bitbucket.org/1.0/repositories/user/repo/branches', false)
|
||||||
)
|
)
|
||||||
->willReturnOnConsecutiveCalls(
|
->willReturnOnConsecutiveCalls(
|
||||||
'{"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}',
|
'{"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}',
|
||||||
'{"node": "937992d19d72", "files": [{"type": "modified", "file": "path/to/file"}], "raw_author": "User <local@domain.tld>", "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}'
|
'{"node": "937992d19d72", "files": [{"type": "modified", "file": "path/to/file"}], "raw_author": "User <local@domain.tld>", "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}',
|
||||||
|
'{}',
|
||||||
|
'{"master": {"node": "937992d19d72", "files": [{"type": "modified", "file": "path/to/file"}], "raw_author": "User <local@domain.tld>", "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}}'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
@ -149,6 +156,9 @@ class GitBitbucketDriverTest extends TestCase
|
||||||
'phpunit/phpunit' => '~4.8'
|
'phpunit/phpunit' => '~4.8'
|
||||||
),
|
),
|
||||||
'time' => '2016-05-17 13:19:52',
|
'time' => '2016-05-17 13:19:52',
|
||||||
|
'support' => array(
|
||||||
|
'source' => 'https://bitbucket.org/user/repo/src/937992d19d72b5116c3e8c4a04f960e5fa270b22/?at=master'
|
||||||
|
)
|
||||||
),
|
),
|
||||||
$driver->getComposerInformation('master')
|
$driver->getComposerInformation('master')
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue