- 2.x - sites settings

- tags
- source-control soft deletes
This commit is contained in:
Saeed Vaziry
2024-10-06 00:04:57 +02:00
parent d1f2add699
commit 3c50e2c947
44 changed files with 972 additions and 119 deletions

View File

@ -2,6 +2,7 @@
namespace App\Models;
use App\Enums\DeploymentStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -37,6 +38,12 @@ class Deployment extends AbstractModel
'commit_data' => 'json',
];
public static array $statusColors = [
DeploymentStatus::DEPLOYING => 'warning',
DeploymentStatus::FINISHED => 'success',
DeploymentStatus::FAILED => 'danger',
];
public function site(): BelongsTo
{
return $this->belongsTo(Site::class);

View File

@ -60,7 +60,8 @@ public function project(): BelongsTo
public static function getByProjectId(int $projectId): Builder
{
return self::query()
->where('project_id', $projectId)
->orWhereNull('project_id');
->where(function (Builder $query) use ($projectId) {
$query->where('project_id', $projectId)->orWhereNull('project_id');
});
}
}

View File

@ -71,8 +71,7 @@ public static function getByProjectId(int $projectId): Builder
{
return self::query()
->where(function (Builder $query) use ($projectId) {
$query->where('project_id', $projectId)
->orWhereNull('project_id');
$query->where('project_id', $projectId)->orWhereNull('project_id');
});
}

View File

@ -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);
}

View File

@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @property string $provider
@ -20,6 +21,7 @@
class SourceControl extends AbstractModel
{
use HasFactory;
use SoftDeletes;
protected $fillable = [
'provider',
@ -61,8 +63,9 @@ public function project(): BelongsTo
public static function getByProjectId(int $projectId): Builder
{
return self::query()
->where('project_id', $projectId)
->orWhereNull('project_id');
->where(function (Builder $query) use ($projectId) {
$query->where('project_id', $projectId)->orWhereNull('project_id');
});
}
public function getImageUrlAttribute(): string

View File

@ -59,8 +59,9 @@ public function project(): BelongsTo
public static function getByProjectId(int $projectId): Builder
{
return self::query()
->where('project_id', $projectId)
->orWhereNull('project_id');
->where(function (Builder $query) use ($projectId) {
$query->where('project_id', $projectId)->orWhereNull('project_id');
});
}
public function getImageUrlAttribute(): string

View File

@ -5,7 +5,6 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
@ -17,7 +16,7 @@
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class Tag extends Model
class Tag extends AbstractModel
{
use HasFactory;
@ -49,7 +48,8 @@ public function sites(): MorphToMany
public static function getByProjectId(int $projectId): Builder
{
return self::query()
->where('project_id', $projectId)
->orWhereNull('project_id');
->where(function (Builder $query) use ($projectId) {
$query->where('project_id', $projectId)->orWhereNull('project_id');
});
}
}