43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\JenkinsMonitorService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class JenkinsMonitorCommand extends Command
|
|
{
|
|
protected $signature = 'jenkins:monitor';
|
|
|
|
protected $description = '轮询 Jenkins 检查新构建并发送钉钉通知';
|
|
|
|
public function handle(JenkinsMonitorService $service): void
|
|
{
|
|
Log::channel('jenkins-monitor')->info('开始检查 Jenkins 构建...');
|
|
|
|
$results = $service->checkAllProjects();
|
|
|
|
if (isset($results['skipped'])) {
|
|
Log::channel('jenkins-monitor')->warning('跳过检查: ' . ($results['reason'] ?? 'unknown'));
|
|
return;
|
|
}
|
|
|
|
foreach ($results as $slug => $result) {
|
|
if (isset($result['skipped'])) {
|
|
Log::channel('jenkins-monitor')->info(sprintf('[%s] 跳过: %s', $slug, $result['reason'] ?? 'unknown'));
|
|
continue;
|
|
}
|
|
|
|
$newBuilds = $result['new_builds'] ?? [];
|
|
if (empty($newBuilds)) {
|
|
Log::channel('jenkins-monitor')->info(sprintf('[%s] 无新构建', $slug));
|
|
} else {
|
|
Log::channel('jenkins-monitor')->info(sprintf('[%s] 发现 %d 个新构建: #%s', $slug, count($newBuilds), implode(', #', $newBuilds)));
|
|
}
|
|
}
|
|
|
|
Log::channel('jenkins-monitor')->info('检查完成');
|
|
}
|
|
}
|