A GitHub Action that fails a pull request if there are any incomplete checklists in the issue body and/or comments. The action is triggered when a pull request is opened or its first comment (the main pull request message) is edited.
Create a file named .github/workflows/require-checklist.yaml
(or any name in that directory), this file will contain the body of your GitHub Action.
This action will default to using the pull_request
or issue
number when used inside a workflow triggered by one of those events. Below is an example of how to use it.
name: Require Checklist
on:
pull_request:
types: [opened, edited, synchronize]
issues:
types: [opened, edited, deleted]
jobs:
job1:
runs-on: ubuntu-latest
steps:
- uses: mheap/require-checklist-action@v2
with:
requireChecklist: false # If this is true and there are no checklists detected, the action will fail
If you would like to use this action outside of a pull_request
or issue
trigger. You can pass in the issue number manually. Note that "issue number" is used even in the context of pull requests.
name: Require Checklist
on:
workflow_run:
workflows: ["Other Workflow"]
types:
- completed
jobs:
job1:
runs-on: ubuntu-latest
steps:
- uses: mheap/require-checklist-action@v2
with:
requireChecklist: false # If this is true and there are no checklists detected, the action will fail
issueNumber: ${{ github.event.workflow_run.pull_requests[0].number }}
Optional checkboxes can be applied with the skipDescriptionRegex
and skipDescriptionRegexFlags
arguments, which correspond to the first and second constructor arguments of Javascript's RegExp class.
Here is an example of skipping any description with including "(Optional)". (case-insensitive).
# ...
jobs:
job1:
runs-on: ubuntu-latest
steps:
- uses: mheap/require-checklist-action@v2
with:
skipDescriptionRegex: .*\(optional\).*
skipDescriptionRegexFlags: i
In case there are some items that are not applicable in given checklist they can be stroked through and this action will ignore them. For example:
- Applicable item
-
Inapplicable item
In case some checkboxes should not be selected at the same time, mark them with TaskRadio <name>
html comment.
E.g.:
- [ ] Identify the cat
- [ ] Pet the cat <!-- TaskRadio one -->
- [ ] Flee the cat <!-- TaskRadio one -->
Will make require only "Pet the cat" or "Flee the cat" to be selected, but not both.
Multiple groups can be present:
- [ ] Identify the cat
- [ ] Pet the cat <!-- TaskRadio one -->
- [ ] Flee the cat <!-- TaskRadio one -->
- [ ] Report the incident <!-- TaskRadio two -->
- [ ] Hide in shame <!-- TaskRadio two -->
Item can belong to multiple groups:
- [ ] Identify the cat
- [ ] Pet the cat <!-- TaskRadio one -->
- [ ] Flee the cat <!-- TaskRadio one -->
- [ ] Report the incident <!-- TaskRadio two -->
- [ ] Hide in shame <!-- TaskRadio two --> <!-- TaskRadio one -->
Existence of a valid combination remains a responsibility of the user.