feat: 展示项目 Jenkins 诊断状态
This commit is contained in:
@@ -29,6 +29,8 @@ import type {
|
||||
PipelineStep,
|
||||
PlatformMessageSummary,
|
||||
ProjectConfig,
|
||||
ProjectJenkinsDiagnosticsSummary,
|
||||
ProjectJenkinsJobDiagnostic,
|
||||
ProjectRefs,
|
||||
ReleaseRun,
|
||||
ReleaseStatus,
|
||||
@@ -349,6 +351,14 @@ export const devopsApi = {
|
||||
return toProjectConfigs(await fetchProjects())
|
||||
},
|
||||
|
||||
async getProjectJenkinsDiagnostics(): Promise<ProjectJenkinsDiagnosticsSummary> {
|
||||
const { data } = await http.get<ProjectJenkinsDiagnosticsSummary>(
|
||||
'/projects/jenkins-diagnostics',
|
||||
)
|
||||
lastDataSource = 'backend'
|
||||
return sanitizeProjectJenkinsDiagnostics(data)
|
||||
},
|
||||
|
||||
async getProjectRefs(projectKey: string): Promise<ProjectRefs> {
|
||||
const { data } = await http.get<ProjectRefs>(`/projects/${projectKey}/refs`)
|
||||
lastDataSource = 'backend'
|
||||
@@ -787,6 +797,8 @@ function toProjectConfigs(backendProjects: BackendProject[]): ProjectConfig[] {
|
||||
lastReleasedAt: '-',
|
||||
lastActor: '-',
|
||||
jenkinsJob: environment.jenkinsJobPath,
|
||||
jenkinsStatus: 'warning' as const,
|
||||
jenkinsMessage: '尚未执行 Jenkins 诊断',
|
||||
wecomRobot: '后端通知配置',
|
||||
}
|
||||
}),
|
||||
@@ -800,6 +812,59 @@ function toProjectConfigs(backendProjects: BackendProject[]): ProjectConfig[] {
|
||||
})
|
||||
}
|
||||
|
||||
function sanitizeProjectJenkinsDiagnostics(
|
||||
value: ProjectJenkinsDiagnosticsSummary,
|
||||
): ProjectJenkinsDiagnosticsSummary {
|
||||
return {
|
||||
checkedAt: safeText(value.checkedAt, new Date().toISOString()),
|
||||
jobs: Array.isArray(value.jobs)
|
||||
? value.jobs.map(sanitizeProjectJenkinsJobDiagnostic)
|
||||
: [],
|
||||
}
|
||||
}
|
||||
|
||||
function sanitizeProjectJenkinsJobDiagnostic(
|
||||
value: ProjectJenkinsJobDiagnostic,
|
||||
): ProjectJenkinsJobDiagnostic {
|
||||
return {
|
||||
projectKey: safeText(value.projectKey, 'unknown-project'),
|
||||
environment: toEnvironmentName(value.environment),
|
||||
jenkinsJobPath: safeText(value.jenkinsJobPath, ''),
|
||||
status: toProjectJenkinsDiagnosticStatus(value.status),
|
||||
message: optionalSafeText(value.message),
|
||||
buildable: typeof value.buildable === 'boolean' ? value.buildable : undefined,
|
||||
url: optionalSafeText(value.url),
|
||||
lastBuild: value.lastBuild
|
||||
? {
|
||||
number: Number.isFinite(value.lastBuild.number)
|
||||
? value.lastBuild.number
|
||||
: undefined,
|
||||
result: value.lastBuild.result,
|
||||
building:
|
||||
typeof value.lastBuild.building === 'boolean'
|
||||
? value.lastBuild.building
|
||||
: undefined,
|
||||
url: optionalSafeText(value.lastBuild.url),
|
||||
}
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
function toProjectJenkinsDiagnosticStatus(
|
||||
value: ProjectJenkinsJobDiagnostic['status'],
|
||||
): ProjectJenkinsJobDiagnostic['status'] {
|
||||
if (
|
||||
value === 'ok' ||
|
||||
value === 'missing' ||
|
||||
value === 'not_configured' ||
|
||||
value === 'unavailable'
|
||||
) {
|
||||
return value
|
||||
}
|
||||
|
||||
return 'unavailable'
|
||||
}
|
||||
|
||||
function toReleaseRun(run: BackendDeployRun, projectList: ProjectConfig[]): ReleaseRun {
|
||||
const projectKey = run.projectKey || 'unknown-project'
|
||||
const project = projectList.find((item) => item.key === projectKey)
|
||||
|
||||
Reference in New Issue
Block a user