Skip to content

Commit dd5b8a6

Browse files
committed
feat(tasks): details text inside github check now shows a table of the checks, required & optional, showing the task name and if its complete or not
1 parent d544c72 commit dd5b8a6

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ module.exports = (app) => {
113113
let commentOutstandingTasks = checkOutstandingTasks(comment.body);
114114
outstandingTasks.total += commentOutstandingTasks.total;
115115
outstandingTasks.remaining += commentOutstandingTasks.remaining;
116+
outstandingTasks.optionalTotal += commentOutstandingTasks.optionalTotal;
117+
outstandingTasks.optionalRemaining += commentOutstandingTasks.optionalRemaining;
118+
outstandingTasks.tasks = (outstandingTasks.tasks || []).concat(commentOutstandingTasks.tasks || []);
119+
outstandingTasks.optionalTasks = (outstandingTasks.optionalTasks || []).concat(commentOutstandingTasks.optionalTasks || []);
116120
});
117121
}
118122

@@ -122,6 +126,25 @@ module.exports = (app) => {
122126
optionalText = ' (+' + outstandingTasks.optionalRemaining + ' optional)';
123127
}
124128

129+
// make a markdown table of the tasks
130+
let tasksTable = '';
131+
if (outstandingTasks.total > 0) {
132+
tasksTable += `
133+
## Required Tasks
134+
| Task | Status |
135+
| ---- | ------ |
136+
${outstandingTasks.tasks.map(task => `| ${task.task} | ${task.status} |`).join('\n')}
137+
`;
138+
}
139+
if (outstandingTasks.optionalTotal > 0) {
140+
tasksTable += `
141+
## Optional Tasks
142+
| Task | Status |
143+
| ---- | ------ |
144+
${outstandingTasks.optionalTasks.map(task => `| ${task.task} | ${task.status} |`).join('\n')}
145+
`;
146+
}
147+
125148
let check = {
126149
name: 'task-list-completed',
127150
head_branch: '',
@@ -131,7 +154,7 @@ module.exports = (app) => {
131154
output: {
132155
title: (outstandingTasks.total - outstandingTasks.remaining) + ' / ' + outstandingTasks.total + ' tasks completed' + optionalText,
133156
summary: outstandingTasks.remaining + ' task' + (outstandingTasks.remaining > 1 ? 's' : '') + ' still to be completed' + optionalText,
134-
text: 'We check if any task lists need completing before you can merge this PR'
157+
text: tasksTable
135158
},
136159
request: {
137160
retries: 3,

src/check-outstanding-tasks.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,21 @@ module.exports = function (body) {
3333

3434
// return counts of task list items and how many are left to be completed
3535
return {
36+
tasks: listItems.filter(item => item.text.indexOf('OPTIONAL') === -1).map(item => {
37+
return {
38+
task: item.text.replace(/\[x\]|\[ \]/, '').trim(),
39+
status: item.checked ? 'Completed' : '**Incomplete**',
40+
};
41+
}),
42+
optionalTasks: optionalItems.map(item => {
43+
return {
44+
task: item.text.replace(/\[x\]|\[ \]/, '').trim(),
45+
status: item.checked ? 'Completed' : '**Incomplete**',
46+
};
47+
}),
3648
total: listItems.filter(item => item.checked !== undefined).length,
3749
remaining: listItems.filter(item => item.checked === false).length,
50+
optionalTotal: optionalItems.filter(item => item.checked !== undefined).length,
3851
optionalRemaining: optionalItems.filter(item => item.checked === false).length
3952
};
4053
};

0 commit comments

Comments
 (0)