Просмотр исходного кода

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

Jordi Boggiano 9 лет назад
Родитель
Сommit
8bfb2e8bc2
1 измененных файлов с 27 добавлено и 10 удалено
  1. 27 10
      src/Composer/Repository/Vcs/GitHubDriver.php

+ 27 - 10
src/Composer/Repository/Vcs/GitHubDriver.php

@@ -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);
-        if (null === $repoData && null !== $this->gitDriver) {
+        $this->repoData = JsonFile::parseJson($this->getContents($repoDataUrl, true), $repoDataUrl);
+        if (null === $this->repoData && null !== $this->gitDriver) {
             return;
             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 {
         } 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()