70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?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 => '未知',
|
|
};
|
|
}
|
|
}
|