From 182fb2a468b47a737e12ef7a2b212430c11d9fcf Mon Sep 17 00:00:00 2001 From: marocchino Date: Tue, 23 Jul 2024 07:44:12 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Fix=20failed=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/comment.test.ts | 2 +- src/comment.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/__tests__/comment.test.ts b/__tests__/comment.test.ts index 7ad8271..b0a75f5 100644 --- a/__tests__/comment.test.ts +++ b/__tests__/comment.test.ts @@ -142,7 +142,7 @@ describe("updateComment", () => { expect(octokit.graphql).toBeCalledWith(expect.any(String), { input: { id: "456", - body: "hello there\n\nhello there" + body: "hello there\nhello there\n" } }) }) diff --git a/src/comment.ts b/src/comment.ts index 0da254a..ff6e0d9 100644 --- a/src/comment.ts +++ b/src/comment.ts @@ -20,7 +20,7 @@ function bodyWithHeader(body: string, header: string): string { } function bodyWithoutHeader(body: string, header: string): string { - return body.replace(`\n${headerComment(header)}`, ""); + return body.replace(`\n${headerComment(header)}`, "") } export async function findPreviousComment( @@ -92,8 +92,9 @@ export async function updateComment( if (!body && !previousBody) return core.warning("Comment body cannot be blank") - if (previousBody) - let rawPreviousBody = bodyWithoutHeader(previousBody, header) + const rawPreviousBody: String = previousBody + ? bodyWithoutHeader(previousBody, header) + : "" await octokit.graphql( `