예제 #1
0
 public function handle()
 {
     $dirs = iterator_to_array(Finder::create()->in($this->repo->releasePath())->depth(0)->sortByChangedTime());
     foreach (array_slice(array_reverse($dirs), 3) as $dir) {
         $this->fs()->deleteDirectory($dir);
     }
 }
예제 #2
0
 public function handle()
 {
     $path = $this->repo->repoPath();
     if (!$this->fs->isDirectory($path) && !$this->fs->makeDirectory($path, 0755, true)) {
         throw new \RuntimeException(sprintf("Cannot create repo dir %s", $path));
     }
     Admin::cloneTo($path, $this->repo->url, true, config('git.options'));
     $this->repo->git()->run('config', ['remote.origin.fetch', 'refs/heads/*:refs/heads/*']);
 }
예제 #3
0
 public function checkCommitsForDeployTags()
 {
     $inv = null;
     $commit = null;
     foreach ($this->commitList as $commit) {
         $parts = explode(" ", $commit['message']);
         if (($index = array_search('@deploy', $parts)) !== false) {
             if (isset($parts[$index + 1])) {
                 $inv = $this->repo->inventories()->where('name', trim($parts[$index + 1]))->get()->first();
                 if ($inv) {
                     break;
                 }
             }
         }
     }
     if ($inv instanceof Inventory && !empty($commit['hash'])) {
         $this->dispatch(new PrepareReleaseJob(Release::create(['repo_id' => $this->repo->id, 'commit' => $commit['hash'], 'status' => Release::QUEUED, 'roles' => ['dogpro.deploy'], 'inventory_id' => $inv->id])));
     }
 }
예제 #4
0
 /**
  * @return mixed|static
  */
 protected function loadRepo()
 {
     $input = $this->argument('repo');
     if ($repo = Repo::whereId($input)->first()) {
         return $repo;
     }
     if ($repo = Repo::whereUrl($input)->first()) {
         return $repo;
     }
     throw new \InvalidArgumentException("Could not find repo {$input}");
 }
예제 #5
0
 /**
  * @return bool
  */
 public function handle()
 {
     if (!$this->removeDir($this->repo->repoPath())) {
         throw new \RuntimeException(sprintf("Failed to delete %s", $this->repo->repoPath()));
     }
     if (!$this->removeDir($this->repo->releasePath())) {
         throw new \RuntimeException(sprintf("Failed to delete %s", $this->repo->releasePath()));
     }
     $this->repo->delete();
 }
예제 #6
0
 /**
  * @return Repo
  */
 public function repo()
 {
     return Repo::query()->where('id', $this->get('repo_id'))->first();
 }
예제 #7
0
 /**
  * @param Repo $repo
  * @param string $commit
  * @return DogproConfig|JsonResponse
  */
 public function config(Repo $repo, $commit)
 {
     $commit = $repo->git()->getCommit($commit);
     if (!$commit) {
         abort(404);
     }
     try {
         $tree = $commit->getTree()->getEntry(DogproConfig::FILENAME);
         if ($tree instanceof Blob) {
             return new DogproConfig($tree->getContent());
         }
     } catch (InvalidArgumentException $e) {
         return response()->json(['error' => 'Configuration file not found!'], 422);
     } catch (ParseException $e) {
         return response()->json(['error' => 'Could not parse configuration file: ' . $e->getMessage()], 422);
     }
     return new JsonResponse(new \stdClass());
 }