#feature: add Jenkins deploy monitor & log clean task
This commit is contained in:
69
app/Models/JenkinsDeployment.php
Normal file
69
app/Models/JenkinsDeployment.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class JenkinsDeployment extends BaseModel
|
||||
{
|
||||
protected $fillable = [
|
||||
'project_id',
|
||||
'build_number',
|
||||
'job_name',
|
||||
'status',
|
||||
'branch',
|
||||
'commit_sha',
|
||||
'triggered_by',
|
||||
'duration',
|
||||
'build_url',
|
||||
'raw_data',
|
||||
'build_params',
|
||||
'notified',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'raw_data' => 'array',
|
||||
'build_params' => 'array',
|
||||
'notified' => 'boolean',
|
||||
];
|
||||
|
||||
public function project(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Project::class);
|
||||
}
|
||||
|
||||
public function getFormattedDuration(): string
|
||||
{
|
||||
if (!$this->duration) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
$seconds = (int) ($this->duration / 1000);
|
||||
$minutes = (int) ($seconds / 60);
|
||||
$seconds = $seconds % 60;
|
||||
|
||||
return sprintf('%02d:%02d', $minutes, $seconds);
|
||||
}
|
||||
|
||||
public function getStatusEmoji(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'SUCCESS' => '✅',
|
||||
'FAILURE' => '❌',
|
||||
'ABORTED' => '⏹️',
|
||||
'UNSTABLE' => '⚠️',
|
||||
default => '❓',
|
||||
};
|
||||
}
|
||||
|
||||
public function getStatusLabel(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'SUCCESS' => '成功',
|
||||
'FAILURE' => '失败',
|
||||
'ABORTED' => '已中止',
|
||||
'UNSTABLE' => '不稳定',
|
||||
default => '未知',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,16 @@ class Project extends BaseModel
|
||||
'git_version_cached_at',
|
||||
'log_app_names',
|
||||
'log_env',
|
||||
'jenkins_job_name',
|
||||
'jenkins_notify_enabled',
|
||||
'jenkins_last_notified_build',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'git_monitor_enabled' => 'boolean',
|
||||
'auto_create_release_branch' => 'boolean',
|
||||
'is_important' => 'boolean',
|
||||
'jenkins_notify_enabled' => 'boolean',
|
||||
'log_app_names' => 'array',
|
||||
'git_version_cached_at' => 'datetime',
|
||||
];
|
||||
@@ -86,4 +90,15 @@ class Project extends BaseModel
|
||||
->whereJsonContains('log_app_names', $appName)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用 Jenkins 通知的项目
|
||||
*/
|
||||
public static function getJenkinsNotifyEnabled(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return static::query()
|
||||
->where('jenkins_notify_enabled', true)
|
||||
->whereNotNull('jenkins_job_name')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
21
app/Models/ScheduledTask.php
Normal file
21
app/Models/ScheduledTask.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ScheduledTask extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'command',
|
||||
'description',
|
||||
'frequency',
|
||||
'cron',
|
||||
'enabled',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'enabled' => 'boolean',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user