From 8bfb2e8bc2cba073eb7cfa1a721bf235337223f6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 9 May 2016 21:40:41 +0100 Subject: [PATCH] Add a getter to fetch the repo data from the outside of the github driver --- src/Composer/Repository/Vcs/GitHubDriver.php | 37 ++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 009f1ce0b..8019e194c 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -30,6 +30,7 @@ class GitHubDriver extends VcsDriver protected $tags; protected $branches; protected $rootIdentifier; + protected $repoData; protected $hasIssues; protected $infoCache = array(); protected $isPrivate = false; @@ -276,6 +277,18 @@ class GitHubDriver extends VcsDriver return true; } + /** + * Gives back the loaded /repos// result + * + * @return array|null + */ + public function getRepoData() + { + $this->fetchRootIdentifier(); + + return $this->repoData; + } + /** * Generate an SSH URL * @@ -400,25 +413,29 @@ class GitHubDriver extends VcsDriver */ protected function fetchRootIdentifier() { + if ($this->repoData) { + return; + } + $repoDataUrl = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository; - $repoData = JsonFile::parseJson($this->getContents($repoDataUrl, true), $repoDataUrl); - if (null === $repoData && null !== $this->gitDriver) { + $this->repoData = JsonFile::parseJson($this->getContents($repoDataUrl, true), $repoDataUrl); + if (null === $this->repoData && null !== $this->gitDriver) { return; } - $this->owner = $repoData['owner']['login']; - $this->repository = $repoData['name']; + $this->owner = $this->repoData['owner']['login']; + $this->repository = $this->repoData['name']; - $this->isPrivate = !empty($repoData['private']); - if (isset($repoData['default_branch'])) { - $this->rootIdentifier = $repoData['default_branch']; - } elseif (isset($repoData['master_branch'])) { - $this->rootIdentifier = $repoData['master_branch']; + $this->isPrivate = !empty($this->repoData['private']); + if (isset($this->repoData['default_branch'])) { + $this->rootIdentifier = $this->repoData['default_branch']; + } elseif (isset($this->repoData['master_branch'])) { + $this->rootIdentifier = $this->repoData['master_branch']; } else { $this->rootIdentifier = 'master'; } - $this->hasIssues = !empty($repoData['has_issues']); + $this->hasIssues = !empty($this->repoData['has_issues']); } protected function attemptCloneFallback()