#feature: add project&cronjob management

This commit is contained in:
2026-01-16 12:14:43 +08:00
parent bbe68839e3
commit 381d5e6e49
19 changed files with 2157 additions and 84 deletions

89
app/Models/Project.php Normal file
View File

@@ -0,0 +1,89 @@
<?php
namespace App\Models;
class Project extends BaseModel
{
protected $fillable = [
'slug',
'name',
'directory',
'absolute_path',
'jira_project_code',
'git_monitor_enabled',
'auto_create_release_branch',
'is_important',
'git_last_checked_commit',
'git_current_version',
'git_release_branch',
'git_version_cached_at',
'log_app_names',
'log_env',
];
protected $casts = [
'git_monitor_enabled' => '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();
}
}