zhaoyingbo f5ee6f8555
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 45s
feat: 修改监控Stage的方式
2024-08-08 11:04:09 +00:00

64 lines
1.8 KiB
TypeScript

import db from "../../db"
import service from "../../service"
import { DB } from "../../types/db"
/**
* 填充项目信息
* @param {DB.Project} project - 项目对象
* @returns {Promise<DB.Project>} - 返回填充后的项目对象
*/
const fillProj = async (project: DB.Project): Promise<DB.Project> => {
const projDetail = await service.gitlab.project.getDetail(project.project_id)
if (!projDetail) {
return project
}
const useFulParams: Partial<DB.Project> = {
...project,
avatar_url: projDetail.avatar_url,
description: projDetail.description,
name: projDetail.name,
path_with_namespace: projDetail.path_with_namespace,
web_url: projDetail.web_url,
}
return await db.project.update(project.id, useFulParams)
}
/**
* 获取到当前所有的项目列表,并把信息不全的项目送给 fillProj 填充内容
* @returns {Promise<DB.Project[]>} - 返回完整的项目列表
*/
const getFullProjList = async (): Promise<DB.Project[]> => {
const fullList = await db.project.getFullList()
// 把信息不全的项目送过去填充
const filledProjList = await Promise.all(
fullList.filter((v) => !v.name).map((item) => fillProj(item))
)
// 合并成完整数据
const filledFullProjList = fullList
.filter((v) => v.name)
.concat(filledProjList)
return filledFullProjList
}
/**
* 获取完整的项目映射表
* @param {DB.Project[]} fullProjList - 完整的项目列表
* @returns {Record<string, string>} - 返回项目映射表
*/
const getFullProjectMap = (
fullProjList: DB.Project[]
): Record<string, string> => {
const fullProjectMap: Record<string, string> = {}
fullProjList.forEach((item) => {
fullProjectMap[item.project_id] = item.id
})
return fullProjectMap
}
const manageProject = {
getFullProjList,
getFullProjectMap,
}
export default manageProject