Skip to content

Commit

Permalink
Add more fine-grained skip
Browse files Browse the repository at this point in the history
  • Loading branch information
dddlr committed Jul 16, 2024
1 parent f522df1 commit 9fefe5e
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions .github/actions/task-checklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /<!--\s*task-checklist-ignore\s*-->/;

// 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 =
/<!--\s*task-checklist-ignore-start\s*-->.*?<!--\s*task-checklist-ignore-end\s*-->/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;
}

Expand All @@ -35,13 +44,13 @@ const run = () => {
console.error(`- ${match}`);
}

console.log('---');
console.info('---');

console.log(
'False positive? Insert <!-- task-checklist-ignore --> in your PR description to skip this check. However, with great power comes great responsibility...'
console.info(
'False positive? Insert <!-- task-checklist-ignore-start --> and <!-- task-checklist-ignore-end --> 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.
Expand Down

0 comments on commit 9fefe5e

Please sign in to comment.