Beispiel #1
0
 public function getBranch()
 {
     $branch =& $this->branch;
     if (!is_null($branch)) {
         return $branch;
     }
     $branches = $this->getBranches();
     $branchName = $this->repo->getBranch();
     $item = null;
     foreach ($branches as $k) {
         if ($k['name'] === $branchName) {
             $item = $k;
             break;
         }
     }
     if (is_null($item)) {
         throw new GitHubException("Branch '{$branchName}' not found");
     }
     // detect cache
     $fn = self::$CacheDir . DIRECTORY_SEPARATOR . $item['commit']['sha'] . '.branch';
     if (file_exists($fn)) {
         $content = file_get_contents($fn);
     } else {
         // make a request
         $url = 'https://api.github.com/repos/' . $this->repo->getUserRepo() . '/branches/' . $this->repo->getBranch();
         $content = $this->getResponse($url, false);
         file_put_contents($fn, $content);
     }
     $branch = json_decode($content, true);
     DONE:
     return $branch;
 }