Skip to content

Commit 20d20a0

Browse files
committed
feat(check): check title now shows counts of complete & total tasks to be completed
1 parent 8c44df4 commit 20d20a0

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = (app) => {
3030
pr = response.data;
3131
}
3232

33-
let hasOutstandingTasks = checkOutstandingTasks(pr.body);
33+
let outstandingTasks = checkOutstandingTasks(pr.body);
3434

3535
// lookup comments on the PR
3636
let comments = await context.github.issues.listComments(context.repo({
@@ -56,9 +56,9 @@ module.exports = (app) => {
5656
// & check them for tasks
5757
if (comments.data.length) {
5858
comments.data.forEach(function (comment) {
59-
if (checkOutstandingTasks(comment.body)) {
60-
hasOutstandingTasks = true;
61-
}
59+
let commentOutstandingTasks = checkOutstandingTasks(comment.body);
60+
outstandingTasks.total += commentOutstandingTasks.total;
61+
outstandingTasks.remaining += commentOutstandingTasks.remaining;
6262
});
6363
}
6464

@@ -68,18 +68,18 @@ module.exports = (app) => {
6868
started_at: startTime,
6969
status: 'in_progress',
7070
output: {
71-
title: 'Outstanding tasks',
72-
summary: 'Tasks still remain to be completed',
71+
title: (outstandingTasks.total - outstandingTasks.remaining) + ' / ' + outstandingTasks.total + ' tasks completed',
72+
summary: outstandingTasks.remaining + ' task' + (outstandingTasks.remaining > 1 ? 's' : '') + ' still to be completed',
7373
text: 'We check if any task lists need completing before you can merge this PR'
7474
}
7575
};
7676

7777
// all finished?
78-
if (hasOutstandingTasks === false) {
78+
console.log(outstandingTasks);
79+
if (outstandingTasks.remaining === 0) {
7980
check.status = 'completed';
8081
check.conclusion = 'success';
8182
check.completed_at = (new Date).toISOString();
82-
check.output.title = 'Tasks completed';
8383
check.output.summary = 'All tasks have been completed';
8484
};
8585

src/check-outstanding-tasks.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ const marked = require('marked');
22

33
module.exports = function (body) {
44
if (body === null) {
5-
return false;
5+
return {
6+
total: 0,
7+
remaining: 0
8+
};
69
}
10+
711
let tokens = marked.lexer(body, { gfm: true });
812
let listItems = tokens.filter(token => token.type === 'list_item_start');
913

10-
// check if it contains any not checked task list items
11-
return listItems.some(item => item.checked === false);
14+
// return counts of task list items and how many are left to be completed
15+
return {
16+
total: listItems.length,
17+
remaining: listItems.filter(item => item.checked === false).length
18+
};
1219
};

tests/index.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ Hello World
88
- [ ] testing
99
- [x] 123
1010
`;
11-
expect(checkOutstandingTasks(markdown)).toBe(true);
11+
let results = checkOutstandingTasks(markdown);
12+
expect(results.total).toBe(2);
13+
expect(results.remaining).toBe(1);
1214
});
1315
test('Test no outstanding tasks', () => {
1416
let markdown = `
1517
Hello World
1618
- [x] testing
1719
- [x] 123
1820
`;
19-
expect(checkOutstandingTasks(markdown)).toBe(false);
21+
let results = checkOutstandingTasks(markdown);
22+
expect(results.total).toBe(2);
23+
expect(results.remaining).toBe(0);
2024
});

0 commit comments

Comments
 (0)