Update GitRepository.php

This commit is contained in:
Bozhidar 2024-09-11 16:16:45 +03:00
parent 91a2cc8240
commit e1a76cf8b5

View file

@ -43,16 +43,16 @@ class GitRepository extends Model
return $this->belongsTo(Domain::class);
}
public function clone()
public function pull()
{
$this->status = self::STATUS_CLONING;
$this->status = self::STATUS_PULLING;
$this->save();
}
public function pull()
public function clone()
{
$this->status = self::STATUS_PULLING;
$this->status = self::STATUS_CLONING;
$this->save();
$findDomain = Domain::find($this->domain_id);
@ -107,18 +107,19 @@ class GitRepository extends Model
return;
}
$cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git';
$shellCommand = [];
if ($gitSSHKey) {
$shellCommand[] = 'git -c core.sshCommand="ssh -i '.$privateKeyFile .'" clone '.$cloneUrl.' '.$projectDir;
$cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git';
$shellCommand[] = 'git -c core.sshCommand="ssh -i '.$privateKeyFile .'" clone '.$cloneUrl.' '.$projectDir . ' 2>&1';
} else {
$shellCommand[] = 'git clone '.$cloneUrl.' '.$projectDir;
$shellCommand[] = 'git clone '.$this->url.' '.$projectDir . ' 2>&1';
}
$shellCommand[] = 'phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-cloned '.$this->id;
$shellCommand[] = 'echo "Cloning completed at $(date)"';
$shellContent = '';
foreach ($shellCommand as $command) {
$shellContent .= $command . "\n";
@ -126,8 +127,9 @@ class GitRepository extends Model
$shellFile = '/tmp/git-clone-' . $this->id . '.sh';
$shellLog = '/tmp/git-clone-' . $this->id . '.log';
file_put_contents($shellFile, $shellContent);
file_put_contents($shellLog, 'Clone started at ' . date('Y-m-d H:i:s') . "\n");
shell_exec('chmod +x ' . $shellFile);
shell_exec('bash '.$shellFile.' >> ' . $shellLog . ' &');