zhaoyingbo 18a95387ee
All checks were successful
CI Monitor CI/CD / build-image (push) Successful in 33s
CI Monitor CI/CD / deploy (push) Successful in 37s
chore: 更新lint-staged和commitlint配置
2024-07-25 01:09:24 +00:00

55 lines
1.4 KiB
TypeScript

import db from "../../db"
import service from "../../service"
import { DB } from "../../types/db"
/**
* 填充项目信息
*/
const fillProj = async (project: 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填充内容
*/
const getFullProjList = async () => {
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
}
const getFullProjectMap = (fullProjList: DB.Project[]) => {
const fullProjectMap: Record<string, string> = {}
fullProjList.forEach((item) => {
fullProjectMap[item.project_id] = item.id
})
return fullProjectMap
}
const manageProject = {
getFullProjList,
getFullProjectMap,
}
export default manageProject