This commit is contained in:
Bozhidar 2024-09-11 16:39:10 +03:00
parent e1a76cf8b5
commit 74360aee69
3 changed files with 32 additions and 13 deletions

View file

@ -28,11 +28,7 @@ class CloneGitRepository extends Page
protected static bool $shouldRegisterNavigation = false;
public $state = [
'url' => '',
'name' => '',
'git_ssh_key_id' => '',
];
public $state = [];
public $repositoryDetails = [];
public function getTitle(): string
@ -66,6 +62,8 @@ class CloneGitRepository extends Page
if (isset($repoDetails['name'])) {
$set('name', $repoDetails['owner'] .'/'. $repoDetails['name']);
$this->repositoryDetails = $repoDetails;
$set('dir', $repoDetails['name']);
}
})
->placeholder('Enter the URL of the repository'),
@ -137,7 +135,6 @@ class CloneGitRepository extends Page
->label('Directory')
->columnSpanFull()
->required()
->default('public_html/')
->placeholder('Enter the directory to clone the repository'),
]),
@ -164,7 +161,11 @@ class CloneGitRepository extends Page
$newGitRepository->dir = $this->state['dir'];
$newGitRepository->clone_from = $this->state['clone_from'];
$newGitRepository->domain_id = $this->state['domain_id'];
$newGitRepository->git_ssh_key_id = (int) $this->state['git_ssh_key_id'];
if (isset($this->state['git_ssh_key_id'])) {
$newGitRepository->git_ssh_key_id = $this->state['git_ssh_key_id'];
}
$newGitRepository->status = GitRepository::STATUS_PENDING;
$newGitRepository->save();

View file

@ -79,14 +79,15 @@ class GitRepositoryResource extends Resource
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('pull')
// ->hidden(fn (GitRepository $record) => $record->status !== 'cloned')
->hidden(fn (GitRepository $record) => $record->status !== 'cloned')
->icon('heroicon-o-arrow-down-tray')
->action(function (GitRepository $record) {
$gitRepository = GitRepository::find($record->id);
$gitRepository->pull();
$gitRepository->clone();
})
}),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
// Tables\Actions\BulkActionGroup::make([

View file

@ -3,6 +3,7 @@
namespace App\Models;
use App\GitClient;
use App\ShellApi;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use function Psy\sh;
@ -36,7 +37,21 @@ class GitRepository extends Model
'domain_id',
'git_ssh_key_id',
];
public static function boot()
{
parent::boot();
static::created(function ($model) {
$model->clone();
});
static::deleting(function ($model) {
$projectDir = $model->domain->domain_root . '/' . $model->dir;
ShellApi::safeDelete($projectDir,[
$model->domain->domain_root . '/',
]);
});
}
public function domain()
{
@ -108,18 +123,20 @@ class GitRepository extends Model
}
$shellCommand = [];
$shellCommand[] = 'echo "Cloning started at $(date)"';
$shellCommand[] = 'export HOME=/home/'.$findHostingSubscription->system_username;
// $shellCommand[] = 'cd '.$findDomain->domain_root;
if ($gitSSHKey) {
$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 '.$this->url.' '.$projectDir . ' 2>&1';
$gitCloneCommand = 'git clone '.$this->url.' '.$projectDir . ' 2>&1';
$shellCommand[] = 'su -m '.$findHostingSubscription->system_username.' -c "'.$gitCloneCommand.'"';
}
$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";