feat: 展示项目 Jenkins 诊断状态
This commit is contained in:
@@ -12,6 +12,7 @@ import type {
|
||||
IntegrationStatus,
|
||||
IntegrationConfigStatus,
|
||||
ProjectConfig,
|
||||
ProjectJenkinsDiagnosticsSummary,
|
||||
ProjectRefs,
|
||||
JenkinsSyncSummary,
|
||||
NotificationOutboxMessage,
|
||||
@@ -123,6 +124,45 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
return refs
|
||||
}
|
||||
|
||||
async function loadProjectJenkinsDiagnostics(): Promise<ProjectJenkinsDiagnosticsSummary> {
|
||||
const diagnostics = await devopsApi.getProjectJenkinsDiagnostics()
|
||||
const jobByEnvironment = new Map(
|
||||
diagnostics.jobs.map((job) => [`${job.projectKey}:${job.environment}`, job]),
|
||||
)
|
||||
|
||||
projects.value = projects.value.map((project) => {
|
||||
const environments = project.environments.map((environment) => {
|
||||
const diagnostic = jobByEnvironment.get(`${project.key}:${environment.name}`)
|
||||
|
||||
if (!diagnostic) {
|
||||
return environment
|
||||
}
|
||||
|
||||
return {
|
||||
...environment,
|
||||
jenkinsJob: diagnostic.jenkinsJobPath || environment.jenkinsJob,
|
||||
jenkinsStatus: jenkinsDiagnosticState(diagnostic.status),
|
||||
jenkinsMessage: diagnostic.message || jenkinsDiagnosticMessage(diagnostic.status),
|
||||
jenkinsUrl: diagnostic.url,
|
||||
jenkinsLastBuild: diagnostic.lastBuild,
|
||||
}
|
||||
})
|
||||
const hasError = environments.some((environment) => environment.jenkinsStatus === 'error')
|
||||
const hasWarning = environments.some((environment) => environment.jenkinsStatus === 'warning')
|
||||
|
||||
return {
|
||||
...project,
|
||||
environments,
|
||||
integrations: {
|
||||
...project.integrations,
|
||||
jenkins: hasError ? 'error' : hasWarning ? 'warning' : 'healthy',
|
||||
},
|
||||
}
|
||||
})
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
async function loadAuditLogs() {
|
||||
auditLogs.value = await devopsApi.getAuditLogs()
|
||||
dataSource.value = devopsApi.getLastDataSource()
|
||||
@@ -171,8 +211,41 @@ export const usePlatformStore = defineStore('platform', () => {
|
||||
syncJenkinsRun,
|
||||
syncJenkinsRuns,
|
||||
loadProjectRefs,
|
||||
loadProjectJenkinsDiagnostics,
|
||||
loadAuditLogs,
|
||||
loadNotificationOutbox,
|
||||
retryNotificationOutboxMessage,
|
||||
}
|
||||
})
|
||||
|
||||
function jenkinsDiagnosticState(
|
||||
status: ProjectJenkinsDiagnosticsSummary['jobs'][number]['status'],
|
||||
) {
|
||||
if (status === 'ok') {
|
||||
return 'healthy' as const
|
||||
}
|
||||
|
||||
if (status === 'not_configured') {
|
||||
return 'warning' as const
|
||||
}
|
||||
|
||||
return 'error' as const
|
||||
}
|
||||
|
||||
function jenkinsDiagnosticMessage(
|
||||
status: ProjectJenkinsDiagnosticsSummary['jobs'][number]['status'],
|
||||
): string {
|
||||
if (status === 'ok') {
|
||||
return 'Jenkins job 可达'
|
||||
}
|
||||
|
||||
if (status === 'missing') {
|
||||
return 'Jenkins job 不存在'
|
||||
}
|
||||
|
||||
if (status === 'not_configured') {
|
||||
return 'Jenkins 集成未配置'
|
||||
}
|
||||
|
||||
return 'Jenkins job 不可用'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user