From e7dcd217fa7d397807470ead36e6deb4f4855387 Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Fri, 2 Aug 2024 03:11:06 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=A9=BA=E5=80=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了在排序过程中出现空值的错误,以确保代码的稳定性和正确性。 --- controllers/managePipelineEvent/index.ts | 6 ++++-- types/gitlab.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/managePipelineEvent/index.ts b/controllers/managePipelineEvent/index.ts index ea6fc61..d928175 100644 --- a/controllers/managePipelineEvent/index.ts +++ b/controllers/managePipelineEvent/index.ts @@ -39,7 +39,9 @@ const checkIsSuccess = async ( if (!stage) return makeResult( pipeline.builds - .sort((a, b) => a.finished_at.localeCompare(b.finished_at))[0] + .sort((a, b) => + (a.finished_at || "").localeCompare(b.finished_at || "") + )[0] .id.toString(), pipeline.object_attributes.status === "success" ) @@ -52,7 +54,7 @@ const checkIsSuccess = async ( return makeResult("", false) // 按finished_at排序,获取最后一个运行的id const lastId = builds.sort((a, b) => - a.finished_at.localeCompare(b.finished_at) + (a.finished_at || "").localeCompare(b.finished_at || "") )[0].id // 该ID的通知是否已经发送过 const notify = await db.notify.getOne(lastId.toString()) diff --git a/types/gitlab.ts b/types/gitlab.ts index bceef33..b9f32d3 100644 --- a/types/gitlab.ts +++ b/types/gitlab.ts @@ -288,7 +288,7 @@ export namespace Gitlab { * 构建的结束时间 * @example 2024-07-29 15:49:21 +0800 */ - finished_at: string + finished_at: string | null }[] }