From 9fefe5ee1d9595c475406975ced1e6ede3ecfa1f Mon Sep 17 00:00:00 2001 From: Grant Wong Date: Tue, 16 Jul 2024 10:52:50 +1000 Subject: [PATCH] Add more fine-grained skip --- .github/actions/task-checklist/index.js | 29 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/actions/task-checklist/index.js b/.github/actions/task-checklist/index.js index 523071e86..168be64ef 100644 --- a/.github/actions/task-checklist/index.js +++ b/.github/actions/task-checklist/index.js @@ -7,25 +7,34 @@ const github = require('@actions/github'); // Also handles whitespace around any of the characters, // and the three different ways to make a list (dash, asterisk, plus) const INCOMPLETE_TASKS_REGEX = /^\s*[-*+]\s+\[ \]\s+(.*)/gm; -const DISABLE_COMMENT_REGEX = //; + +// This regex finds regions which we should EXCLUDE from the task checklist action. +// +// - s flag required so that ".*?" matches over multiple lines +// - "?" in ".*?" ensures that we match the smallest possible string +// - note that m flag is not required. +const DISABLE_COMMENT_REGEX = + /.*?/gs; const run = () => { const body = github.context.payload.pull_request?.body; if (!body) { - console.log('PR description empty, skipping this check.'); + console.info('PR description empty, skipping this check.'); return; } - const disableCommentMatch = body.match(DISABLE_COMMENT_REGEX); - if (disableCommentMatch) { - console.log('Found "task-checklist-ignore" comment - skipping checklist tasks.'); + const bodyWithoutDisables = body.replace(DISABLE_COMMENT_REGEX, ''); + if (body !== bodyWithoutDisables) { + console.debug( + 'Found at least one "task-checklist-ignore-start"/"task-checklist-ignore-end" block.' + ); return; } const matches = [...body.matchAll(INCOMPLETE_TASKS_REGEX)].map((match) => match[1]); if (!matches.length) { - console.log('No tasks marked as incomplete. Great work!'); + console.info('No tasks marked as incomplete. Great work!'); return; } @@ -35,13 +44,13 @@ const run = () => { console.error(`- ${match}`); } - console.log('---'); + console.info('---'); - console.log( - 'False positive? Insert in your PR description to skip this check. However, with great power comes great responsibility...' + console.info( + 'False positive? Insert and in the sections of your PR where you want to skip the check. However, with great power comes great responsibility...' ); - console.log('---'); + console.info('---'); core.setFailed(` Found at least one item in the PR description not marked as completed.