Add a getter to fetch the repo data from the outside of the github driver

main
Jordi Boggiano 8 years ago
parent 0040498e25
commit 8bfb2e8bc2

@ -30,6 +30,7 @@ class GitHubDriver extends VcsDriver
protected $tags; protected $tags;
protected $branches; protected $branches;
protected $rootIdentifier; protected $rootIdentifier;
protected $repoData;
protected $hasIssues; protected $hasIssues;
protected $infoCache = array(); protected $infoCache = array();
protected $isPrivate = false; protected $isPrivate = false;
@ -276,6 +277,18 @@ class GitHubDriver extends VcsDriver
return true; return true;
} }
/**
* Gives back the loaded <github-api>/repos/<owner>/<repo> result
*
* @return array|null
*/
public function getRepoData()
{
$this->fetchRootIdentifier();
return $this->repoData;
}
/** /**
* Generate an SSH URL * Generate an SSH URL
* *
@ -400,25 +413,29 @@ class GitHubDriver extends VcsDriver
*/ */
protected function fetchRootIdentifier() protected function fetchRootIdentifier()
{ {
if ($this->repoData) {
return;
}
$repoDataUrl = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository; $repoDataUrl = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository;
$repoData = JsonFile::parseJson($this->getContents($repoDataUrl, true), $repoDataUrl); $this->repoData = JsonFile::parseJson($this->getContents($repoDataUrl, true), $repoDataUrl);
if (null === $repoData && null !== $this->gitDriver) { if (null === $this->repoData && null !== $this->gitDriver) {
return; return;
} }
$this->owner = $repoData['owner']['login']; $this->owner = $this->repoData['owner']['login'];
$this->repository = $repoData['name']; $this->repository = $this->repoData['name'];
$this->isPrivate = !empty($repoData['private']); $this->isPrivate = !empty($this->repoData['private']);
if (isset($repoData['default_branch'])) { if (isset($this->repoData['default_branch'])) {
$this->rootIdentifier = $repoData['default_branch']; $this->rootIdentifier = $this->repoData['default_branch'];
} elseif (isset($repoData['master_branch'])) { } elseif (isset($this->repoData['master_branch'])) {
$this->rootIdentifier = $repoData['master_branch']; $this->rootIdentifier = $this->repoData['master_branch'];
} else { } else {
$this->rootIdentifier = 'master'; $this->rootIdentifier = 'master';
} }
$this->hasIssues = !empty($repoData['has_issues']); $this->hasIssues = !empty($this->repoData['has_issues']);
} }
protected function attemptCloneFallback() protected function attemptCloneFallback()

Loading…
Cancel
Save