57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Actions\Git\Data\GitRepository;
|
|
use App\Actions\Git\GitProviderKey;
|
|
use Database\Factories\RepositoryConnectionFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
#[Fillable([
|
|
'base_url',
|
|
'owner_name',
|
|
'project_id',
|
|
'provider',
|
|
'provider_repository_id',
|
|
'repository_full_name',
|
|
'repository_name',
|
|
'repository_url',
|
|
])]
|
|
class RepositoryConnection extends Model
|
|
{
|
|
/** @use HasFactory<RepositoryConnectionFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'provider' => GitProviderKey::class,
|
|
];
|
|
}
|
|
|
|
public function project(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function toGitRepository(): GitRepository
|
|
{
|
|
return new GitRepository(
|
|
baseUrl: $this->base_url,
|
|
providerRepositoryId: $this->provider_repository_id,
|
|
owner: $this->owner_name,
|
|
name: $this->repository_name,
|
|
fullName: $this->repository_full_name,
|
|
htmlUrl: $this->repository_url,
|
|
defaultBranch: null,
|
|
isPrivate: false,
|
|
);
|
|
}
|
|
}
|