Use the repository rather than the project ID, so if a single
repo is used in multiple projects it is not duplicated.
public mirrorPath ( ) : string | ||
Résultat | string |
/** * Execute the job. * @throws \RuntimeException * @dispatches UpdateGitReferences */ public function handle() { $private_key = tempnam(storage_path('app/'), 'sshkey'); file_put_contents($private_key, $this->project->private_key); $wrapper = with(new ScriptParser())->parseFile('tools.SSHWrapperScript', ['private_key' => $private_key]); $wrapper_file = tempnam(storage_path('app/'), 'gitssh'); file_put_contents($wrapper_file, $wrapper); $process = new Process('tools.MirrorGitRepository', ['wrapper_file' => $wrapper_file, 'mirror_path' => $this->project->mirrorPath(), 'repository' => $this->project->repository]); $process->run(); unlink($wrapper_file); unlink($private_key); if (!$process->isSuccessful()) { throw new \RuntimeException('Could not mirror repository - ' . $process->getErrorOutput()); } $this->project->last_mirrored = date('Y-m-d H:i:s'); $this->project->save(); $this->dispatch(new UpdateGitReferences($this->project)); }
/** * 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']); } } } }