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 = {