This commit is contained in:
Bozhidar 2024-09-11 16:10:06 +03:00
parent c6403abd86
commit 91a2cc8240
4 changed files with 95 additions and 5 deletions

View file

@ -0,0 +1,66 @@
<?php
namespace Modules\Customer\App\Console;
use App\Models\GitRepository;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class GitRepositoryMarkAsCloned extends Command
{
/**
* The name and signature of the console command.
*/
protected $signature = 'git-repository:mark-as-cloned {id}';
/**
* The console command description.
*/
protected $description = 'Command description.';
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
$id = $this->argument('id');
$repository = GitRepository::find($id);
if (!$repository) {
$this->error('Repository not found.');
return;
}
$repository->status = GitRepository::STATUS_CLONED;
$repository->save();
}
/**
* Get the console command arguments.
*/
protected function getArguments(): array
{
return [
['id', InputArgument::REQUIRED, 'Git repository ID.'],
];
}
/**
* Get the console command options.
*/
protected function getOptions(): array
{
return [
['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
];
}
}

View file

@ -79,7 +79,7 @@ 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) {

View file

@ -4,6 +4,7 @@ namespace Modules\Customer\App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Customer\App\Console\GitRepositoryMarkAsCloned;
use Modules\Customer\App\Providers\Filament\CustomerPanelProvider;
class CustomerServiceProvider extends ServiceProvider
@ -39,7 +40,9 @@ class CustomerServiceProvider extends ServiceProvider
*/
protected function registerCommands(): void
{
// $this->commands([]);
$this->commands([
GitRepositoryMarkAsCloned::class
]);
}
/**

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\GitClient;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use function Psy\sh;
class GitRepository extends Model
{
@ -106,10 +107,30 @@ class GitRepository extends Model
return;
}
// $cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git';
// $clone = shell_exec('git -c core.sshCommand="ssh -i '.$privateKeyFile.'" clone ' . $cloneUrl . ' ' . $projectDir);
$cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git';
// dd($clone);
$shellCommand = [];
if ($gitSSHKey) {
$shellCommand[] = 'git -c core.sshCommand="ssh -i '.$privateKeyFile .'" clone '.$cloneUrl.' '.$projectDir;
} else {
$shellCommand[] = 'git clone '.$cloneUrl.' '.$projectDir;
}
$shellCommand[] = 'phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-cloned '.$this->id;
$shellContent = '';
foreach ($shellCommand as $command) {
$shellContent .= $command . "\n";
}
$shellFile = '/tmp/git-clone-' . $this->id . '.sh';
$shellLog = '/tmp/git-clone-' . $this->id . '.log';
file_put_contents($shellFile, $shellContent);
shell_exec('chmod +x ' . $shellFile);
shell_exec('bash '.$shellFile.' >> ' . $shellLog . ' &');
}