From bcc0eb0fd7779c0b9d6c99d4905566127c54846f Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Mon, 8 Jul 2024 02:39:57 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=8E=B7=E5=8F=96pipline=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/managePipeLine/index.ts | 5 ++++ schedule/syncPipLine.ts | 2 +- service/gitlab.ts | 37 ++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/controllers/managePipeLine/index.ts b/controllers/managePipeLine/index.ts index ebd7f7a..dc6c1f6 100644 --- a/controllers/managePipeLine/index.ts +++ b/controllers/managePipeLine/index.ts @@ -26,6 +26,8 @@ const getFullPipelineList = async (project: ProjectRecordModel) => { // 如果当前页没有数据,则直接跳出 if (pipelines.length === 0) break; pipelines.forEach((pipeline) => { + // 如果已经有了比最新的pipeline还要早的pipeline,则跳出 + if (hasBeforeLatestTime) return; if (moment(pipeline.created_at).isSameOrBefore(latestTime)) { hasBeforeLatestTime = true; } else { @@ -52,6 +54,9 @@ const insertFullPipelineList = async ( fullPipelineList.forEach((pipelineList) => { pipelineList.forEach((pipeline) => { + // 如果没有时间信息,则跳过 + if (!pipeline.created_at || !pipeline.started_at || !pipeline.finished_at) + return; dbPipelineList.push({ project_id: fullProjectMap[pipeline.project_id], user_id: fullUserMap[pipeline.user.id], diff --git a/schedule/syncPipLine.ts b/schedule/syncPipLine.ts index c4e6245..bbfb67b 100644 --- a/schedule/syncPipLine.ts +++ b/schedule/syncPipLine.ts @@ -16,4 +16,4 @@ const syncPipLine = async () => { ); }; -export default syncPipLine; \ No newline at end of file +export default syncPipLine; diff --git a/service/gitlab.ts b/service/gitlab.ts index aa59832..be6d0c7 100644 --- a/service/gitlab.ts +++ b/service/gitlab.ts @@ -4,7 +4,10 @@ const AUTH_HEADER = { "PRIVATE-TOKEN": "Zd1UASPcMwVox5tNS6ep" }; const BASE_URL = "https://git.n.xiaomi.com/api/v4"; -const gitlabReqWarp = async (func: Function, default_value: any) => { +const gitlabReqWarp = async ( + func: Function, + default_value: any +): Promise => { try { let response = {} as T & GitlabError; response = (await func()) as T & GitlabError; @@ -13,7 +16,7 @@ const gitlabReqWarp = async (func: Function, default_value: any) => { } catch { return default_value; } -} +}; /** * 获取项目详情 @@ -23,7 +26,10 @@ const gitlabReqWarp = async (func: Function, default_value: any) => { const fetchProjectDetails = async (id: number | string) => { if (typeof id === "string") id = encodeURIComponent(id); const URL = `${BASE_URL}/projects/${id}`; - return gitlabReqWarp(() => netTool.get(URL, {}, AUTH_HEADER), null); + return gitlabReqWarp( + () => netTool.get(URL, {}, AUTH_HEADER), + null + ); }; /** @@ -35,7 +41,10 @@ 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 gitlabReqWarp(() => netTool.get(URL, params, AUTH_HEADER), []); + return gitlabReqWarp( + () => netTool.get(URL, params, AUTH_HEADER), + [] + ); }; /** @@ -51,7 +60,10 @@ const fetchPipelineDetails = async ( created_at: string ) => { const URL = `${BASE_URL}/projects/${project_id}/pipelines/${pipeline_id}`; - const res = gitlabReqWarp(() => netTool.get(URL, {}, AUTH_HEADER), null); + const res = await gitlabReqWarp( + () => netTool.get(URL, {}, AUTH_HEADER), + null + ); if (res === null) return null; return { ...res, created_at }; }; @@ -62,7 +74,10 @@ const fetchPipelineDetails = async ( */ const fetchProjectBadges = async (project_id: number) => { const URL = `${BASE_URL}/projects/${project_id}/badges`; - return gitlabReqWarp(() => netTool.get(URL, {}, AUTH_HEADER), []); + return gitlabReqWarp( + () => netTool.get(URL, {}, AUTH_HEADER), + [] + ); }; /** @@ -71,7 +86,10 @@ const fetchProjectBadges = async (project_id: number) => { */ const setProjectBadge = async (badge: GitlabBadgeSetParams) => { const URL = `${BASE_URL}/projects/${badge.id}/badges/${badge.badge_id}`; - return gitlabReqWarp(() => netTool.put(URL, badge, AUTH_HEADER), null); + return gitlabReqWarp( + () => netTool.put(URL, badge, AUTH_HEADER), + null + ); }; /** @@ -80,7 +98,10 @@ const setProjectBadge = async (badge: GitlabBadgeSetParams) => { */ const addProjectBadge = async (badge: GitlabBadgeSetParams) => { const URL = `${BASE_URL}/projects/${badge.id}/badges`; - return gitlabReqWarp(() => netTool.post(URL, badge, {}, AUTH_HEADER), null); + return gitlabReqWarp( + () => netTool.post(URL, badge, {}, AUTH_HEADER), + null + ); }; const gitlab = {