From 524320c0e85d6584f8851a538f588295e5fa2a46 Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Thu, 4 Jul 2024 02:41:11 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96GitLab=E5=BE=BD?= =?UTF-8?q?=E7=AB=A0=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- badge/cloudml.ts | 11 +++++++---- service/gitlab.ts | 25 ++++++++++--------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/badge/cloudml.ts b/badge/cloudml.ts index 066224c..fc74fbf 100644 --- a/badge/cloudml.ts +++ b/badge/cloudml.ts @@ -14,8 +14,8 @@ const projectList = [ "cloud-ml/cloudml_syncqueue", "cloud-ml/resource-instance", "cloud-ml/ai-workbench-common", - "cloud-ml/evaluate.git", - "ai-service-data/ai-train-platform-service.git", + "cloud-ml/evaluate", + "ai-service-data/ai-train-platform-service", "cloud-ml/embedding_management", "cloud-ml/knowledge-base", "cloud-ml/ai-proxy", @@ -44,10 +44,13 @@ const getNewProjectBadge = async ( ]; const diff = [...badgeNameList].filter((x) => !badgeNameSet.has(x)); const newBadges: GitlabBadgeSetParams[] = diff.map((name) => { - const link_url = `https://sonarqube.mioffice.cn/dashboard?id=${sonarqubeId}`; + const link_url = encodeURI( + `https://sonarqube.mioffice.cn/dashboard?id=${sonarqubeId}` + ); + const metric = name.replace("sonarqube_", ""); const image_url = name !== "sonarqube_quality_gate" - ? `https://sonarqube.mioffice.cn/api/badges/measure?key=${sonarqubeId}&metric=${name}` + ? `https://sonarqube.mioffice.cn/api/badges/measure?key=${sonarqubeId}&metric=${metric}` : `https://sonarqube.mioffice.cn/api/badges/gate?key=${sonarqubeId}`; return { id: projectDetail.id, diff --git a/service/gitlab.ts b/service/gitlab.ts index d489a04..aa59832 100644 --- a/service/gitlab.ts +++ b/service/gitlab.ts @@ -4,21 +4,16 @@ const AUTH_HEADER = { "PRIVATE-TOKEN": "Zd1UASPcMwVox5tNS6ep" }; const BASE_URL = "https://git.n.xiaomi.com/api/v4"; -const gitlabReq = async ( - url: string, - params: any, - default_value: any, - reqFunc: any = netTool.get -): Promise => { +const gitlabReqWarp = async (func: Function, default_value: any) => { try { - const response = (await reqFunc(url, params, AUTH_HEADER)) as T & - GitlabError; + let response = {} as T & GitlabError; + response = (await func()) as T & GitlabError; if (response.message === "404 Project Not Found") return default_value; return response; } catch { return default_value; } -}; +} /** * 获取项目详情 @@ -28,7 +23,7 @@ const gitlabReq = async ( const fetchProjectDetails = async (id: number | string) => { if (typeof id === "string") id = encodeURIComponent(id); const URL = `${BASE_URL}/projects/${id}`; - return gitlabReq(URL, {}, null); + return gitlabReqWarp(() => netTool.get(URL, {}, AUTH_HEADER), null); }; /** @@ -40,7 +35,7 @@ const fetchProjectDetails = async (id: number | string) => { const fetchPipelines = async (project_id: number, page = 1) => { const URL = `${BASE_URL}/projects/${project_id}/pipelines`; const params = { scope: "finished", per_page: 100, page }; - return gitlabReq(URL, params, []); + return gitlabReqWarp(() => netTool.get(URL, params, AUTH_HEADER), []); }; /** @@ -56,7 +51,7 @@ const fetchPipelineDetails = async ( created_at: string ) => { const URL = `${BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}`; - const res = gitlabReq(URL, {}, null); + const res = gitlabReqWarp(() => netTool.get(URL, {}, AUTH_HEADER), null); if (res === null) return null; return { ...res, created_at }; }; @@ -67,7 +62,7 @@ const fetchPipelineDetails = async ( */ const fetchProjectBadges = async (project_id: number) => { const URL = `${BASE_URL}/projects/${project_id}/badges`; - return gitlabReq(URL, {}, []); + return gitlabReqWarp(() => netTool.get(URL, {}, AUTH_HEADER), []); }; /** @@ -76,7 +71,7 @@ const fetchProjectBadges = async (project_id: number) => { */ const setProjectBadge = async (badge: GitlabBadgeSetParams) => { const URL = `${BASE_URL}/projects/${badge.id}/badges/${badge.badge_id}`; - return gitlabReq(URL, badge, null, netTool.put); + return gitlabReqWarp(() => netTool.put(URL, badge, AUTH_HEADER), null); }; /** @@ -85,7 +80,7 @@ const setProjectBadge = async (badge: GitlabBadgeSetParams) => { */ const addProjectBadge = async (badge: GitlabBadgeSetParams) => { const URL = `${BASE_URL}/projects/${badge.id}/badges`; - return gitlabReq(URL, badge, null, netTool.post); + return gitlabReqWarp(() => netTool.post(URL, badge, {}, AUTH_HEADER), null); }; const gitlab = {