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

47 lines
1.1 KiB
TypeScript

import db from "../../db"
import { Gitlab } from "../../types/gitlab"
/**
* 获取完整的用户映射表
* @param {Gitlab.PipelineDetail[][]} fullPipelineList - 完整的pipeline列表
* @returns {Promise<Record<string, string>>} - 返回用户映射表
*/
const getFullUserMap = async (
fullPipelineList: Gitlab.PipelineDetail[][]
): Promise<Record<string, string>> => {
const userList: Gitlab.User[] = []
fullPipelineList.forEach((fullPipeline) => {
fullPipeline.forEach((item) => {
if (item.user && !userList.find((v) => v.id === item.user?.id)) {
userList.push(item.user)
}
})
})
const dbUserInfo = await Promise.all(
userList
.filter((v) => v.id !== 0)
.map((user) =>
db.user.upsert({
user_id: user.id,
username: user.username,
name: user.name,
avatar_url: user.avatar_url,
web_url: user.web_url,
})
)
)
const userMap: Record<string, string> = {}
dbUserInfo.forEach((item) => {
if (!item) return
userMap[item.user_id] = item.id
})
return userMap
}
const manageUser = {
getFullUserMap,
}
export default manageUser