1
0
Fork 0

Guess issues/source support info for github packages

pull/747/merge
Jordi Boggiano 2012-05-31 10:54:12 +02:00
parent ad90187adf
commit 2257d0b550
1 changed files with 14 additions and 7 deletions

View File

@ -29,6 +29,7 @@ class GitHubDriver extends VcsDriver
protected $tags; protected $tags;
protected $branches; protected $branches;
protected $rootIdentifier; protected $rootIdentifier;
protected $hasIssues;
protected $infoCache = array(); protected $infoCache = array();
protected $isPrivate = false; protected $isPrivate = false;
@ -106,7 +107,7 @@ class GitHubDriver extends VcsDriver
return $this->gitDriver->getDist($identifier); return $this->gitDriver->getDist($identifier);
} }
$label = array_search($identifier, $this->getTags()) ?: $identifier; $label = array_search($identifier, $this->getTags()) ?: $identifier;
$url = $this->getScheme() . '://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$label; $url = 'https://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$label;
return array('type' => 'zip', 'url' => $url, 'reference' => $label, 'shasum' => ''); return array('type' => 'zip', 'url' => $url, 'reference' => $label, 'shasum' => '');
} }
@ -126,7 +127,7 @@ class GitHubDriver extends VcsDriver
if (!isset($this->infoCache[$identifier])) { if (!isset($this->infoCache[$identifier])) {
try { try {
$composer = $this->getContents($this->getScheme() . '://raw.github.com/'.$this->owner.'/'.$this->repository.'/'.$identifier.'/composer.json'); $composer = $this->getContents('https://raw.github.com/'.$this->owner.'/'.$this->repository.'/'.$identifier.'/composer.json');
} catch (TransportException $e) { } catch (TransportException $e) {
if (404 !== $e->getCode()) { if (404 !== $e->getCode()) {
throw $e; throw $e;
@ -139,10 +140,15 @@ class GitHubDriver extends VcsDriver
$composer = JsonFile::parseJson($composer); $composer = JsonFile::parseJson($composer);
if (!isset($composer['time'])) { if (!isset($composer['time'])) {
$commit = JsonFile::parseJson($this->getContents($this->getScheme() . '://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/commits/'.$identifier)); $commit = JsonFile::parseJson($this->getContents('https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/commits/'.$identifier));
$composer['time'] = $commit['commit']['committer']['date']; $composer['time'] = $commit['commit']['committer']['date'];
} }
if (!isset($composer['support']['source'])) {
$composer['support']['source'] = sprintf('https://github.com/%s/%s/tree/%s', $this->owner, $this->repository, $identifier);
}
if (!isset($composer['support']['issues']) && $this->hasIssues) {
$composer['support']['issues'] = sprintf('https://github.com/%s/%s/issues', $this->owner, $this->repository);
}
} }
if (preg_match('{[a-f0-9]{40}}i', $identifier)) { if (preg_match('{[a-f0-9]{40}}i', $identifier)) {
@ -164,7 +170,7 @@ class GitHubDriver extends VcsDriver
return $this->gitDriver->getTags(); return $this->gitDriver->getTags();
} }
if (null === $this->tags) { if (null === $this->tags) {
$tagsData = JsonFile::parseJson($this->getContents($this->getScheme() . '://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/tags')); $tagsData = JsonFile::parseJson($this->getContents('https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/tags'));
$this->tags = array(); $this->tags = array();
foreach ($tagsData as $tag) { foreach ($tagsData as $tag) {
$this->tags[$tag['name']] = $tag['commit']['sha']; $this->tags[$tag['name']] = $tag['commit']['sha'];
@ -183,7 +189,7 @@ class GitHubDriver extends VcsDriver
return $this->gitDriver->getBranches(); return $this->gitDriver->getBranches();
} }
if (null === $this->branches) { if (null === $this->branches) {
$branchData = JsonFile::parseJson($this->getContents($this->getScheme() . '://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/git/refs/heads')); $branchData = JsonFile::parseJson($this->getContents('https://api.github.com/repos/'.$this->owner.'/'.$this->repository.'/git/refs/heads'));
$this->branches = array(); $this->branches = array();
foreach ($branchData as $branch) { foreach ($branchData as $branch) {
$name = substr($branch['ref'], 11); $name = substr($branch['ref'], 11);
@ -231,7 +237,7 @@ class GitHubDriver extends VcsDriver
*/ */
protected function fetchRootIdentifier() protected function fetchRootIdentifier()
{ {
$repoDataUrl = $this->getScheme() . '://api.github.com/repos/'.$this->owner.'/'.$this->repository; $repoDataUrl = 'https://api.github.com/repos/'.$this->owner.'/'.$this->repository;
$attemptCounter = 0; $attemptCounter = 0;
while (null === $this->rootIdentifier) { while (null === $this->rootIdentifier) {
if (5 == $attemptCounter++) { if (5 == $attemptCounter++) {
@ -246,6 +252,7 @@ class GitHubDriver extends VcsDriver
} else { } else {
$this->rootIdentifier = 'master'; $this->rootIdentifier = 'master';
} }
$this->hasIssues = !empty($repoData['has_issues']);
} catch (TransportException $e) { } catch (TransportException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
case 401: case 401: