refactoring

This commit is contained in:
Saeed Vaziry
2023-08-06 17:36:39 +02:00
parent 643318fcfc
commit a8295e15c3
28 changed files with 239 additions and 66 deletions

View File

@ -3,6 +3,7 @@
namespace App\Actions\PHP;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Validation\ValidationException;
class UninstallPHP
@ -11,6 +12,7 @@ public function uninstall(Server $server, string $version): void
{
$this->validate($server, $version);
/** @var Service $php */
$php = $server->services()->where('type', 'php')->where('version', $version)->first();
$php->uninstall();

View File

@ -6,7 +6,7 @@
class UpdateEnv
{
public function handle(Site $site, array $input): void
public function update(Site $site, array $input): void
{
$typeData = $site->type_data;
$typeData['env'] = $input['env'];

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\Livewire\Application;
use App\Actions\Site\UpdateEnv;
use App\Models\Site;
use App\Traits\RefreshComponentOnBroadcast;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class Env extends Component
{
use RefreshComponentOnBroadcast;
public Site $site;
public string $env;
public function mount(): void
{
$this->env = $this->site->env;
}
public function save(): void
{
app(UpdateEnv::class)->update($this->site, $this->all());
session()->flash('status', 'updating-env');
$this->emit(Deploy::class, '$refresh');
}
public function render(): View
{
return view('livewire.application.env');
}
}

View File

@ -26,7 +26,9 @@ public function handle(): void
new EditFileCommand(
$this->site->path.'/.env',
$this->site->env
)
),
'update-env',
$this->site->id
);
event(
new Broadcast('deploy-site-env-finished', [

View File

@ -0,0 +1,25 @@
<?php
namespace App\SSHCommands\System;
use App\SSHCommands\Command;
use Illuminate\Support\Facades\File;
class ReadFileCommand extends Command
{
public function __construct(protected string $path)
{
}
public function file(): string
{
return File::get(resource_path('commands/system/read-file.sh'));
}
public function content(): string
{
return str($this->file())
->replace('__path__', $this->path)
->toString();
}
}

View File

@ -3,7 +3,11 @@
namespace App\SourceControlProviders;
use App\Exceptions\FailedToDeployGitHook;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\FailedToDestroyGitHook;
use App\Exceptions\RepositoryNotFound;
use App\Exceptions\RepositoryPermissionDenied;
use App\Exceptions\SourceControlIsNotConnected;
use Exception;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
@ -102,9 +106,22 @@ public function getLastCommit(string $repo, string $branch): ?array
return null;
}
/**
* @throws FailedToDeployGitKey
*/
public function deployKey(string $title, string $repo, string $key): void
{
// TODO: Implement deployKey() method.
$res = Http::withToken($this->sourceControl->access_token)->post(
$this->apiUrl."/repositories/$repo/deploy-keys",
[
'label' => $title,
'key' => $key,
]
);
if ($res->status() != 201) {
throw new FailedToDeployGitKey($res->json()['error']['message']);
}
}
protected function getCommitter(string $raw): array

View File

@ -125,7 +125,7 @@ public function deployKey(string $title, string $repo, string $key): void
$response = Http::withToken($this->sourceControl->access_token)->post(
$this->apiUrl.'/projects/'.$repository.'/deploy_keys',
[
'title' => 'deploy-key',
'title' => $title,
'key' => $key,
'can_push' => true,
]