mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
- 2.x - sites settings
- tags - source-control soft deletes
This commit is contained in:
@ -9,7 +9,6 @@
|
||||
use App\SSH\Services\Webserver\Webserver;
|
||||
use App\Traits\HasProjectThroughServer;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
@ -42,6 +41,7 @@
|
||||
* @property Ssl[] $ssls
|
||||
* @property ?Ssl $activeSsl
|
||||
* @property string $ssh_key_name
|
||||
* @property ?SourceControl $sourceControl
|
||||
*/
|
||||
class Site extends AbstractModel
|
||||
{
|
||||
@ -157,38 +157,14 @@ public function tags(): MorphToMany
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SourceControlIsNotConnected
|
||||
*/
|
||||
public function sourceControl(): SourceControl|HasOne|null|Model
|
||||
public function sourceControl(): BelongsTo
|
||||
{
|
||||
$sourceControl = null;
|
||||
|
||||
if (! $this->source_control && ! $this->source_control_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->source_control) {
|
||||
$sourceControl = SourceControl::query()->where('provider', $this->source_control)->first();
|
||||
}
|
||||
|
||||
if ($this->source_control_id) {
|
||||
$sourceControl = SourceControl::query()->find($this->source_control_id);
|
||||
}
|
||||
|
||||
if (! $sourceControl) {
|
||||
throw new SourceControlIsNotConnected($this->source_control);
|
||||
}
|
||||
|
||||
return $sourceControl;
|
||||
return $this->belongsTo(SourceControl::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SourceControlIsNotConnected
|
||||
*/
|
||||
public function getFullRepositoryUrl()
|
||||
public function getFullRepositoryUrl(): ?string
|
||||
{
|
||||
return $this->sourceControl()->provider()->fullRepoUrl($this->repository, $this->getSshKeyName());
|
||||
return $this->sourceControl?->provider()?->fullRepoUrl($this->repository, $this->getSshKeyName());
|
||||
}
|
||||
|
||||
public function getAliasesString(): string
|
||||
@ -259,13 +235,13 @@ public function enableAutoDeployment(): void
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->sourceControl()?->getRepo($this->repository)) {
|
||||
if (! $this->sourceControl?->getRepo($this->repository)) {
|
||||
throw new SourceControlIsNotConnected($this->source_control);
|
||||
}
|
||||
|
||||
$gitHook = new GitHook([
|
||||
'site_id' => $this->id,
|
||||
'source_control_id' => $this->sourceControl()->id,
|
||||
'source_control_id' => $this->source_control_id,
|
||||
'secret' => Str::uuid()->toString(),
|
||||
'actions' => ['deploy'],
|
||||
'events' => ['push'],
|
||||
@ -279,7 +255,7 @@ public function enableAutoDeployment(): void
|
||||
*/
|
||||
public function disableAutoDeployment(): void
|
||||
{
|
||||
if (! $this->sourceControl()?->getRepo($this->repository)) {
|
||||
if (! $this->sourceControl?->getRepo($this->repository)) {
|
||||
throw new SourceControlIsNotConnected($this->source_control);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user