2023-03-28 10:09:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
class GithubApp extends BaseModel
|
|
|
|
{
|
2023-05-09 12:42:10 +00:00
|
|
|
protected $fillable = ['name', 'uuid', 'organization', 'api_url', 'html_url', 'custom_user', 'custom_port', 'team_id'];
|
2023-04-19 12:00:31 +00:00
|
|
|
protected $casts = [
|
|
|
|
'is_public' => 'boolean',
|
|
|
|
];
|
2023-05-10 09:02:59 +00:00
|
|
|
protected static function booted(): void
|
|
|
|
{
|
|
|
|
static::deleting(function (GithubApp $github_app) {
|
|
|
|
$applications_count = Application::where('source_id', $github_app->id)->count();
|
|
|
|
if ($applications_count > 0) {
|
|
|
|
throw new \Exception('You cannot delete this GitHub App because it is in use by ' . $applications_count . ' application(s). Delete them first.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-03-28 10:09:34 +00:00
|
|
|
public function applications()
|
|
|
|
{
|
|
|
|
return $this->morphMany(Application::class, 'source');
|
|
|
|
}
|
2023-03-30 09:09:39 +00:00
|
|
|
public function privateKey()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(PrivateKey::class);
|
|
|
|
}
|
2023-05-08 09:51:03 +00:00
|
|
|
static public function public()
|
|
|
|
{
|
|
|
|
return GithubApp::where('team_id', session('currentTeam')->id)->where('is_public', true)->get();
|
|
|
|
}
|
|
|
|
static public function private()
|
|
|
|
{
|
2023-05-09 07:54:43 +00:00
|
|
|
return GithubApp::where('team_id', session('currentTeam')->id)->where('is_public', false)->get();
|
2023-05-08 09:51:03 +00:00
|
|
|
}
|
2023-03-28 10:09:34 +00:00
|
|
|
}
|