/** * Execute the job. */ public function handle() { $mirror_dir = $this->project->mirrorPath(); $this->project->refs()->delete(); foreach (['tag', 'branch'] as $ref) { $process = new Process('tools.ListGitReferences', ['mirror_path' => $mirror_dir, 'git_reference' => $ref]); $process->run(); if ($process->isSuccessful()) { foreach (explode(PHP_EOL, trim($process->getOutput())) as $reference) { $reference = trim($reference); if (empty($reference)) { continue; } if (substr($reference, 0, 1) === '*') { $reference = trim(substr($reference, 1)); } Ref::create(['name' => $reference, 'project_id' => $this->project->id, 'is_tag' => $ref === 'tag']); } } } }
/** * Clones the repository locally to get the latest log entry and updates * the deployment model. */ private function updateRepoInfo() { $commit = $this->deployment->commit === Deployment::LOADING ? null : $this->deployment->commit; $process = new Process('tools.GetCommitDetails', ['mirror_path' => $this->deployment->project->mirrorPath(), 'git_reference' => $commit ?: $this->deployment->branch]); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException('Could not get repository info - ' . $process->getErrorOutput()); } $git_info = $process->getOutput(); list($commit, $committer, $email) = explode("\t", $git_info); $this->deployment->commit = $commit; $this->deployment->committer = trim($committer); $this->deployment->committer_email = trim($email); if (!$this->deployment->user_id && !$this->deployment->source) { $user = User::where('email', $this->deployment->committer_email)->first(); if ($user) { $this->deployment->user_id = $user->id; } } $this->deployment->save(); }