114 lines
3.3 KiB
TypeScript
114 lines
3.3 KiB
TypeScript
import service from "../../service"
|
|
import { BadgeSetParams } from "../../service/gitlab/badge"
|
|
import { Gitlab } from "../../types/gitlab"
|
|
|
|
const projectList = [
|
|
"miai-fe/fe/ai-admin-fe",
|
|
"miai-fe/fe/ai-operation-fe",
|
|
"miai-fe/fe/ai-dripback-fe",
|
|
"miai-fe/fe/ai-open-admin-fe",
|
|
"miai-fe/fe/ai-model-deployment-fe",
|
|
"miai-fe/fe/ai-workbench",
|
|
"miai-fe/fe/ai-review-fe",
|
|
"miai-fe/fe/cms",
|
|
"miai-fe/fe/xiaoai-open-Platform",
|
|
"miai-fe/fe/ai-robot-fe",
|
|
"miai-fe/fe/ai-scene-review-fe",
|
|
"miai-fe/fe/houyi",
|
|
"miai-fe/fe/kms",
|
|
"miai-fe/fe/ai-productive-fe",
|
|
"miai-fe/fe/ai-sliding-label-fe",
|
|
"miai-fe/fe/ai-label-control-fe",
|
|
"miai-fe/fe/asr-fe",
|
|
"miai-fe/fe/feedback-platform-fe",
|
|
"miai-fe/fe/statisfaction-evaluation-platform-fe",
|
|
"miai-fe/fe/ai-quality-score-fe",
|
|
"miai-fe/fe/wakeup",
|
|
"miai-fe/fe/ai-badcase-label-fe",
|
|
"miai-fe/fe/func-manager",
|
|
"miai-fe/service/ado-server",
|
|
"miai-fe/fe/ado-fe",
|
|
"miai-fe/pwa/ai-rn-domain",
|
|
"miai-fe/pwa/ai-ak-fe",
|
|
"miai-fe/fe/ai-user-info-fe",
|
|
"miai-fe/fe-infra/xiaoai-jssdk",
|
|
"miai-fe/fe-infra/ai-ui",
|
|
"miai-fe/fe/ai-class-sheducle-fe",
|
|
"miai-fe/service/ai-schedule-service",
|
|
"miai-fe/fe/ai-schedule-devtool-v3",
|
|
"miai-fe/ai-scenes-fe",
|
|
"miai-fe/activity/om-music-tone",
|
|
"miai-fe/activity/ug-guide-test",
|
|
"miai-fe/activity/om-mood-blindbox",
|
|
"miai-fe/activity/om-love-poem",
|
|
"miai-fe/fe/ai-introduce",
|
|
"miai-fe/fe/ai-phonecall-guider-fe",
|
|
"miai-fe/activity/om-spring-couplets",
|
|
"miai-fe/activity/ug-play-assistant",
|
|
"miai-fe/fe/ai-iot-introduce-fe",
|
|
"miai-fe/fe/ai-rookie-play-fe",
|
|
"miai-fe/fe/ai-custom-tts-fe",
|
|
"miai-fe/fe-infra/split-rpk-sdk",
|
|
"miai-fe/fe/ai-full-animation-template-fe",
|
|
"miai-fe/fe/ai-schedule-manager-fe",
|
|
"miai-fe/fe/ai-voiceprint-fe",
|
|
"miai-fe/fe/ai-shortcut-fe",
|
|
]
|
|
|
|
const getProjectId = async (projectName: string) => {
|
|
const res = await service.gitlab.project.getDetail(projectName)
|
|
return res?.id
|
|
}
|
|
|
|
const getNewProjectBadge = async (
|
|
projectId: number
|
|
): Promise<BadgeSetParams[]> => {
|
|
const badges: Gitlab.Badge[] = await service.gitlab.badge.get(projectId)
|
|
|
|
const replacePath = (value: string) =>
|
|
value.replace(
|
|
"https://sonarqube.mioffice.cn",
|
|
"http://scan.sonarqube.xiaomi.srv"
|
|
)
|
|
|
|
return badges.map((badge: Gitlab.Badge) => ({
|
|
id: projectId,
|
|
badge_id: badge.id,
|
|
link_url: replacePath(badge.link_url),
|
|
image_url: badge.image_url,
|
|
rendered_image_url: badge.rendered_image_url,
|
|
rendered_link_url: replacePath(badge.rendered_link_url),
|
|
}))
|
|
}
|
|
|
|
const setNewProjectBadge = async (badgeSetParamsList: BadgeSetParams[]) => {
|
|
const chunkSize = 5 // 每次并发请求的数量
|
|
for (let i = 0; i < badgeSetParamsList.length; i += chunkSize) {
|
|
const chunk = badgeSetParamsList.slice(i, i + chunkSize)
|
|
const res = await Promise.all(
|
|
chunk.map((badgeSetParams) => service.gitlab.badge.set(badgeSetParams))
|
|
)
|
|
console.log(res)
|
|
}
|
|
}
|
|
|
|
const main = async () => {
|
|
const errorList: string[] = []
|
|
const badgeSetParamsList = await Promise.all(
|
|
projectList.map(async (projectName) => {
|
|
const projectId = await getProjectId(projectName)
|
|
if (!projectId) {
|
|
errorList.push(projectName)
|
|
return []
|
|
}
|
|
return await getNewProjectBadge(projectId)
|
|
})
|
|
)
|
|
|
|
await setNewProjectBadge(badgeSetParamsList.flat())
|
|
|
|
console.log("errorList", errorList)
|
|
}
|
|
|
|
main()
|