#add git monitor

This commit is contained in:
2025-12-18 10:18:25 +08:00
parent 2ec44b5665
commit 5f6bba1d9f
18 changed files with 889 additions and 20 deletions

View File

@@ -18,16 +18,15 @@ class EnvCommand extends Command
private EnvService $envManager;
public function __construct(EnvService $envManager)
public function __construct()
{
parent::__construct();
$this->envManager = $envManager;
}
public function handle(): int
{
$action = $this->argument('action');
$this->envManager ??= app(EnvService::class);
try {
switch ($action) {
case 'list':
@@ -93,7 +92,7 @@ class EnvCommand extends Command
private function listEnvironments(): int
{
$project = $this->option('project');
if (!$project) {
$this->error('请指定项目名称: --project=项目名');
return 1;
@@ -136,7 +135,7 @@ class EnvCommand extends Command
if ($this->confirm("确定要将 {$environment} 环境应用到项目 {$project} 吗?")) {
$success = $this->envManager->applyEnv($project, $environment);
if ($success) {
$this->info("成功将 {$environment} 环境应用到项目 {$project}");
return 0;
@@ -178,7 +177,7 @@ class EnvCommand extends Command
}
$success = $this->envManager->saveEnv($project, $environment, $content);
if ($success) {
$this->info("成功保存环境配置 {$project}/{$environment}");
return 0;
@@ -202,7 +201,7 @@ class EnvCommand extends Command
}
$success = $this->envManager->importFromProject($project, $environment);
if ($success) {
$this->info("成功从项目 {$project} 导入环境配置为 {$environment}");
return 0;
@@ -227,7 +226,7 @@ class EnvCommand extends Command
if ($this->confirm("确定要删除环境配置 {$project}/{$environment} 吗?")) {
$success = $this->envManager->deleteEnv($project, $environment);
if ($success) {
$this->info("成功删除环境配置 {$project}/{$environment}");
return 0;
@@ -359,9 +358,9 @@ class EnvCommand extends Command
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, 2) . ' ' . $units[$pow];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Console\Commands;
use App\Services\GitMonitorService;
use Illuminate\Console\Command;
class GitMonitorCacheCommand extends Command
{
protected $signature = 'git-monitor:cache';
protected $description = '刷新 release 版本缓存,保存到 configs 表';
public function handle(GitMonitorService $monitor): void
{
$cache = $monitor->refreshReleaseCache(true);
if (empty($cache)) {
$this->warn('未获取到任何 release 版本信息,请检查配置。');
return;
}
$this->info(sprintf(
'已缓存 %d 个仓库的 release 分支信息。',
count($cache['repositories'] ?? [])
));
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use App\Services\GitMonitorService;
use Illuminate\Console\Command;
class GitMonitorCheckCommand extends Command
{
protected $signature = 'git-monitor:check
{--force-cache : 强制从 JIRA 刷新 release 缓存后再检查}';
protected $description = '巡检 release 分支是否包含 develop merge 或因为冲突导致的函数缺失';
public function handle(GitMonitorService $monitor): void
{
if ($this->option('force-cache')) {
$monitor->refreshReleaseCache(true);
} else {
$monitor->ensureReleaseCache();
}
$results = $monitor->checkRepositories(false);
foreach ($results as $repo => $result) {
if (isset($result['error'])) {
$this->error(sprintf('[%s] %s', $repo, $result['error']));
continue;
}
$this->line(sprintf(
'[%s] 分支 %s 已对齐 %s扫描 %d 个提交。',
$repo,
$result['branch'],
$result['head'],
$result['commits_scanned']
));
if (!empty($result['issues']['develop_merges'])) {
$this->warn(sprintf(' - 检测到 %d 个 develop merge', count($result['issues']['develop_merges'])));
}
if (!empty($result['issues']['missing_functions'])) {
$this->warn(sprintf(' - 检测到 %d 个疑似缺失函数的提交', count($result['issues']['missing_functions'])));
}
}
}
}