From cbe3af53a04287127acd10e31a4b93fa930c085c Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Wed, 3 Jan 2024 13:21:24 +0000 Subject: [PATCH] Add support for skipping checklists in comments --- action.yml | 4 ++++ index.js | 16 +++++++++------- index.test.js | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index cdb846e..58b609b 100644 --- a/action.yml +++ b/action.yml @@ -15,3 +15,7 @@ inputs: description: Require a checklist to exist required: false default: "false" + skipComments: + description: Do not look for checklists in comments + required: false + default: "false" diff --git a/index.js b/index.js index ae4dcf6..c8f159a 100644 --- a/index.js +++ b/index.js @@ -30,13 +30,15 @@ async function action() { bodyList.push(issue.body); } - const { data: comments } = await octokit.rest.issues.listComments({ - ...github.context.repo, - issue_number: issueNumber, - }); - - for (let comment of comments) { - bodyList.push(comment.body); + if (core.getInput("skipComments") != "true") { + const { data: comments } = await octokit.rest.issues.listComments({ + ...github.context.repo, + issue_number: issueNumber, + }); + + for (let comment of comments) { + bodyList.push(comment.body); + } } // Check each comment for a checklist diff --git a/index.test.js b/index.test.js index 4a5e7ba..a749621 100644 --- a/index.test.js +++ b/index.test.js @@ -272,6 +272,21 @@ describe("Require Checklist", () => { expect(core.setFailed).toBeCalledWith( "The following items are not marked as completed: Two, Three" ); + + delete process.env.INPUT_ISSUENUMBER; + }); + + it("ignores checklists in comments when skipComments is enabled", async () => { + process.env.INPUT_REQUIRECHECKLIST = "false"; + process.env.INPUT_SKIPCOMMENTS = "true"; + mockIssueBody("Nothing in the body"); + + console.log = jest.fn(); + await action(tools); + + expect(console.log).toBeCalledWith( + "There are no incomplete task list items" + ); }); });