Example #1
0
 public function getBranchesToSync()
 {
     $allowedBranches = $this->setting('sync.sync.branches');
     if (count($allowedBranches) === 0) {
         return [];
     }
     $branchesToSync = [];
     $branches = $this->github->repositories()->branches($this->setting('owner'), $this->setting('repository'));
     foreach ($branches as $branch) {
         $branchName = $branch['name'];
         if (!in_array('*', $allowedBranches, true) and !in_array($branchName, $allowedBranches, true)) {
             continue;
         }
         $sha = $branch['commit']['sha'];
         $cacheKey = md5($this->project->getName() . $branchName);
         $branch = $this->cache->get($cacheKey, false);
         $destinationPath = Path::join($this->project->getPath(), $branchName);
         if ($branch !== $sha or $branch === false or !$this->files->exists($destinationPath)) {
             $branchesToSync[] = $branchName;
         }
     }
     return $branchesToSync;
 }