/** * 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(); }
/** * Clones the repository locally to get the latest log entry and updates * the deployment model. * * @return void */ private function updateRepoInfo() { $wrapper = tempnam(storage_path() . '/app/', 'gitssh'); file_put_contents($wrapper, $this->gitWrapperScript($this->private_key)); $workingdir = tempnam(storage_path() . '/app/', 'clone'); unlink($workingdir); $cmd = <<<CMD chmod +x "{$wrapper}" && \\ export GIT_SSH="{$wrapper}" && \\ git clone --quiet --branch %s --depth 1 %s {$workingdir} && \\ cd {$workingdir} && \\ git checkout %s --quiet && \\ git log --pretty=format:"%%H%%x09%%an%%x09%%ae" && \\ rm -rf {$workingdir} CMD; $process = new Process(sprintf($cmd, $this->deployment->branch, $this->deployment->project->repository, $this->deployment->branch)); $process->setTimeout(null); $process->run(); unlink($wrapper); if (!$process->isSuccessful()) { throw new \RuntimeException('Could not get repository info - ' . $process->getErrorOutput()); } $git_info = $process->getOutput(); $parts = explode("\t", $git_info); $this->deployment->commit = $parts[0]; $this->deployment->committer = trim($parts[1]); if (!$this->deployment->user_id && !$this->deployment->source) { $user = User::where('email', trim($parts[2]))->first(); if ($user) { $this->deployment->user_id = $user->id; } } $this->deployment->save(); }