From da6fd3b3a24f40ca13ff34a2ad31845b0fa302a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Mar 2026 11:46:47 +0000 Subject: [PATCH] feat: refactor option validation to list-based approach and add delete+hide_and_recreate check Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> --- __tests__/main.test.ts | 17 +++++++++++++---- src/main.ts | 24 ++++++++++-------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 8ddc0af..ddfdbae 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -115,7 +115,7 @@ describe("run", () => { mockConfig.recreate = true const {core} = await runMain() expect(core.setFailed).toHaveBeenCalledWith( - "delete and recreate cannot be both set to true", + "delete and recreate cannot be set to true simultaneously", ) }) @@ -124,7 +124,7 @@ describe("run", () => { mockConfig.onlyCreateComment = true const {core} = await runMain() expect(core.setFailed).toHaveBeenCalledWith( - "delete and only_create cannot be both set to true", + "delete and only_create cannot be set to true simultaneously", ) }) @@ -133,7 +133,7 @@ describe("run", () => { mockConfig.hideOldComment = true const {core} = await runMain() expect(core.setFailed).toHaveBeenCalledWith( - "delete and hide cannot be both set to true", + "delete and hide cannot be set to true simultaneously", ) }) @@ -151,7 +151,16 @@ describe("run", () => { mockConfig.hideAndRecreate = true const {core} = await runMain() expect(core.setFailed).toHaveBeenCalledWith( - "hide and hide_and_recreate cannot be both set to true", + "hide and hide_and_recreate cannot be set to true simultaneously", + ) + }) + + test("fails when deleteOldComment and hideAndRecreate are both true", async () => { + mockConfig.deleteOldComment = true + mockConfig.hideAndRecreate = true + const {core} = await runMain() + expect(core.setFailed).toHaveBeenCalledWith( + "delete and hide_and_recreate cannot be set to true simultaneously", ) }) diff --git a/src/main.ts b/src/main.ts index 790bda7..aa165a3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -46,26 +46,22 @@ async function run(): Promise { throw new Error("Either message or path input is required") } - if (deleteOldComment && recreate) { - throw new Error("delete and recreate cannot be both set to true") - } - - if (deleteOldComment && onlyCreateComment) { - throw new Error("delete and only_create cannot be both set to true") - } - - if (deleteOldComment && hideOldComment) { - throw new Error("delete and hide cannot be both set to true") + const exclusiveModes: [string, boolean][] = [ + ["delete", deleteOldComment], + ["recreate", recreate], + ["only_create", onlyCreateComment], + ["hide", hideOldComment], + ["hide_and_recreate", hideAndRecreate], + ] + const enabledModes = exclusiveModes.filter(([, flag]) => flag).map(([name]) => name) + if (enabledModes.length > 1) { + throw new Error(`${enabledModes.join(" and ")} cannot be set to true simultaneously`) } if (onlyCreateComment && onlyUpdateComment) { throw new Error("only_create and only_update cannot be both set to true") } - if (hideOldComment && hideAndRecreate) { - throw new Error("hide and hide_and_recreate cannot be both set to true") - } - const octokit = github.getOctokit(githubToken) const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)