-
Notifications
You must be signed in to change notification settings - Fork 1
/
eventHandler_gollum.js
34 lines (28 loc) · 1.11 KB
/
eventHandler_gollum.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const a = require('./eventAccessors.js');
const pageLink = (page, formatter, esc) => formatter.format_link(page.html_url, esc(page.page_name));
const calculatePageChange = (page, formatter, esc) => `${pageLink(page, formatter, esc)} was ${page.action}`;
const calculatePageChanges = (pages, formatter, esc) => {
const newPages = pages.map(val => calculatePageChange(val, formatter, esc));
if (newPages.length < 2) {
return newPages[0] || 'no pages updated';
}
let result = '';
const len = newPages.length;
newPages.forEach((page, ix) => {
if (ix === len-1) {
result = `${result} and ${page}`;
} else {
result = `${result}, ${page}`;
}
});
return result;
};
module.exports = (e, {subjectFormatter: sf, messageFormatter: mf, escaper: esc}) => {
const pages = calculatePageChanges(e.pages, mf, esc);
let subject = `${sf.format_front(e, a)} created or modified one or more wiki pages`;
let message = `${mf.format_front(e, a)} modified these pages: ${pages}`;
return {
subject: subject,
message: message,
};
};