'boolean', 'auto_create_release_branch' => 'boolean', 'is_important' => 'boolean', 'log_app_names' => 'array', 'git_version_cached_at' => 'datetime', ]; /** * 获取项目的完整路径 */ public function getFullPath(string $projectsPath): string { if (!empty($this->absolute_path)) { return rtrim($this->absolute_path, '/'); } $directory = $this->directory ?? $this->slug; return rtrim($projectsPath, '/') . '/' . ltrim($directory, '/'); } /** * 检查项目路径是否有效 */ public function isPathValid(string $projectsPath): bool { $path = $this->getFullPath($projectsPath); return is_dir($path); } /** * 检查是否是有效的 Git 仓库 */ public function isGitRepository(string $projectsPath): bool { $path = $this->getFullPath($projectsPath); return is_dir($path . DIRECTORY_SEPARATOR . '.git'); } /** * 根据 slug 查找项目 */ public static function findBySlug(string $slug): ?self { return static::query()->where('slug', $slug)->first(); } /** * 获取所有启用 Git 监控的项目 */ public static function getGitMonitorEnabled(): \Illuminate\Database\Eloquent\Collection { return static::query()->where('git_monitor_enabled', true)->get(); } /** * 根据 app 名称查找项目 */ public static function findByAppName(string $appName): ?self { return static::query() ->whereJsonContains('log_app_names', $appName) ->first(); } }