Skip to content

Commit

Permalink
Added support for inapplicable checklist items (#28)
Browse files Browse the repository at this point in the history
* Added support for inapplicable checklist items
* Update readme
  • Loading branch information
martinssipenko committed Nov 23, 2022
1 parent 2d826a5 commit 65a96e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
### Inapplicable checklist items
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:
- [X] Applicable item
- [ ] ~Inapplicable item~
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Toolkit } = require("actions-toolkit");
const TASK_LIST_ITEM = /(?:^|\n)\s*-\s+\[([ xX])\]\s+(.*)/g;
const TASK_LIST_ITEM = /(?:^|\n)\s*-\s+\[([ xX])\]\s+((?!~).*)/g;

Toolkit.run(async (tools) => {
const bodyList = [];
Expand Down
30 changes: 30 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ describe("Require Checklist", () => {
);
});

it("handles checklist with inapplicable items in body", async () => {
mockIssueBody("Demo\r\n\r\n- [x] One\r\n- [ ] ~Two~");
mockIssueComments(["No checklist in comment"]);

tools.log.success = jest.fn();
tools.exit.success = jest.fn();
await action(tools);

expect(tools.log.success).toBeCalledWith("Completed task list item: One");

expect(tools.exit.success).toBeCalledWith(
"There are no incomplete task list items"
);
});

it("handles incomplete checklist in comments", async () => {
mockIssueBody("Nothing in the body");
mockIssueComments(["Demo\r\n\r\n- [x] One\r\n- [ ] Two\n- [ ] Three"]);
Expand All @@ -111,6 +126,21 @@ describe("Require Checklist", () => {
);
});

it("handles checklist with inapplicable items in comments", async () => {
mockIssueBody("Nothing in the body");
mockIssueComments(["Demo\r\n\r\n- [x] One\r\n- [ ] ~Two~"]);

tools.log.success = jest.fn();
tools.exit.success = jest.fn();
await action(tools);

expect(tools.log.success).toBeCalledWith("Completed task list item: One");

expect(tools.exit.success).toBeCalledWith(
"There are no incomplete task list items"
);
});

it("handles issues with empty body, requireChecklist disabled", async () => {
process.env.INPUT_REQUIRECHECKLIST = "false";

Expand Down

0 comments on commit 65a96e6

Please sign in to comment.