forked from olabiniV2/repo-notifications-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventHandler_issues.js
57 lines (52 loc) · 2.6 KB
/
eventHandler_issues.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const a = require('./eventAccessors.js');
module.exports = (e, {subjectFormatter: sf, messageFormatter: mf}) => {
let subject = '';
let message = '';
switch(e.action) {
case 'opened':
subject = `${sf.format_front(e, a)} opened an issue ${sf.format_issue(e, a)}`;
message = `${mf.format_front(e, a)} opened an issue ${mf.format_issue(e, a)}. nl nl '${e.issue.body}'.`;
break;
case 'reopened':
case 'closed':
case 'edited':
case 'deleted':
case 'locked':
case 'unlocked':
case 'pinned':
case 'unpinned':
case 'transferred':
subject = `${sf.format_front(e, a)} ${e.action} issue ${sf.format_issue(e, a)}`;
message = `${mf.format_front(e, a)} ${e.action} issue ${mf.format_issue(e, a)}.`;
break;
case 'assigned':
case 'unassigned':
let referent = 'to';
if (e.action === 'unassigned') {
referent = 'from';
}
subject = `${sf.format_front(e, a)} ${e.action} ${sf.format_link_simple(a.assignee_url(e), a.assignee(e))} ${referent} issue ${sf.format_issue(e, a)}`;
message = `${mf.format_front(e, a)} ${e.action} ${mf.format_link_simple(a.assignee_url(e), a.assignee(e))} ${referent} issue ${mf.format_issue(e, a)}.`;
break;
case 'labeled':
subject = `${sf.format_front(e, a)} added the label '${e.label.name}' to issue ${sf.format_issue(e, a)}`;
message = `${mf.format_front(e, a)} added the label '${e.label.name}' to issue ${mf.format_issue(e, a)}.`;
break;
case 'unlabeled':
subject = `${sf.format_front(e, a)} removed the label '${e.label.name}' from issue ${sf.format_issue(e, a)}`;
message = `${mf.format_front(e, a)} removed the label '${e.label.name}' from issue ${mf.format_issue(e, a)}.`;
break;
case 'milestoned':
subject = `${sf.format_front(e, a)} set the milestone for issue ${sf.format_issue(e, a)} to '${sf.format_link_simple(e.milestone.html_url, e.milestone.title)}'`;
message = `${mf.format_front(e, a)} set the milestone for issue ${mf.format_issue(e, a)} to '${mf.format_link_simple(e.milestone.html_url, e.milestone.title)}'.`;
break;
case 'demilestoned':
subject = `${sf.format_front(e, a)} removed the milestone '${sf.format_link_simple(e.milestone.html_url, e.milestone.title)}' from issue ${sf.format_issue(e, a)}`;
message = `${mf.format_front(e, a)} removed the milestone '${mf.format_link_simple(e.milestone.html_url, e.milestone.title)}' from issue ${mf.format_issue(e, a)}.`;
break;
}
return {
subject: subject,
message: message,
};
};