-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
201 lines (185 loc) · 8.03 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const { includes } = require("resium");
const core = require('@actions/core');
const github = require('@actions/github');
const nodemailer = require('nodemailer');
const issue = github.context.payload.issue;
const email_password = core.getInput('email_password');
const email_username = core.getInput('sender_email');
const email_to = core.getInput('recipient_email').split(';');
core.debug(issue)
const keywords_lists = [
["privacy", "theft", "steal", "leak"],
["safety", "security", "concern"],
["data", "password", "profile"],
["send", "user", "Microsoft","content"]
]
core.debug(issue)
main(email_username, email_password, email_to, issue)
function main(email_username, email_password, email_to, issue) {
var need_attention = false;
try {
//any word in the 1st item of keywords_lists
if ((issue.title.match(new RegExp(keywords_lists[0].join('|', 'gi')))) ||
(issue.body.match(new RegExp(keywords_lists[0].join('|', 'gi'))))){
setOutput_sendEmail(email_username, email_password, email_to, issue);
need_attention = true;
}
else{
//4 words coexist in the 4th item of keywords_lists
if (keywords_lists[3].every(coexist_keywords =>
(issue.title.includes(coexist_keywords) || issue.body.includes(coexist_keywords)))){
setOutput_sendEmail(email_username, email_password, email_to, issue);
need_attention = true;
}else{
//any word from 2nd item shows together with any word from 3nd item in the keywords_lists
for (let i = 0; i < keywords_lists[1].length; i++) {
const firstKeyword = keywords_lists[1][i];
for (let j = 0; j < keywords_lists[2].length; j++) {
const secondKeyword = keywords_lists[2][j];
if ((issue.title.match(new RegExp(`\\b${firstKeyword}\\b.*\\b${secondKeyword}\\b`, 'gi'))) ||
(issue.body.match(new RegExp(`\\b${firstKeyword}\\b.*\\b${secondKeyword}\\b`, 'gi')))) {
setOutput_sendEmail(email_username, email_password, email_to, issue);
need_attention = true;
break;
}
}
if (need_attention) {
break;
}
}
}
}
if (!need_attention) {
core.setOutput("need_attention", 'false');
}
}
catch (err) {
core.setFailed(`Error ${err}`);
}
}
function setOutput_sendEmail(email_username, email_password, email_to, issue) {
var data = {
"title": "privacy",
"issueName": issue.title,
"issueLink": issue.html_url,
"issueNumber": issue.number,
"issueCreateTime": issue.created_at
}
var jsonData = JSON.stringify(data);
core.setOutput("need_attention", 'true');
core.setOutput("issue_info", jsonData);
core.notice("Alarm: new high priority issue need to look into!\n" + issue.html_url)
try {
sendMail(email_username, email_password, email_to, issue);
} catch (err) {
core.error(err.message)
}
}
function sendMail(email_username, email_password, email_to, issue) {
const emailContent = `
<html>
<body style="background-color:grey">
<table align="center" border="0" cellpadding="0" cellspacing="0"
width="550" bgcolor="white" style="border:2px solid black">
<tbody>
<tr>
<td align="center">
<table align="center" border="0" cellpadding="0"
cellspacing="0" class="col-550" width="550">
<tbody>
<tr>
<td align="center" style="background-color: #188cd9;;
height: 50px;">
<a href="#" style="text-decoration: none;">
<p style="color:white;
font-weight:bold; font-size: 18px">
GitHub Auto-Digest Bot
</p>
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr style="height: 300px;">
<td align="center" style="border: none;
border-bottom: 2px solid #188cd9;
padding-right: 20px;padding-left:20px">
<p style="font-weight: bolder;font-size: 42px;
letter-spacing: 0.025em;
color:red" class="small">
Alarm!
</p>
<p style="font-weight: bolder;font-size: 36px;
letter-spacing: 0.025em;
color:black" class="small">
New high priority issue need to look into!
</p>
</td>
</tr>
<tr style="display: inline-block;">
<td style="height: 150px;
padding: 20px;
border: none;
border-bottom: 2px solid #361B0E;
background-color: white;">
<h2 style="text-align: left; align-items: center;">
Issue Title: ${issue.title}
</h2>
<p class="data"
style="text-align: justify-all;
align-items: center;
font-size: 15px;
padding-bottom: 12px;">
Issue Number: ${issue.number}
</p>
<p class="data"
style="text-align: justify-all;
align-items: center;
font-size: 15px;
padding-bottom: 12px;">
Issue Create Time: ${issue.created_at}
</p>
<p>
<a href="${issue.html_url}"
style="text-decoration: none;
color:black;
border: 2px solid #188cd9;
padding: 10px 30px;
font-weight: bold;">
View Issue
</a>
</p>
</td>
</tr>
</tbody>
</table>
</body>
</html>
`
let transporter = nodemailer.createTransport({
host: 'primary.exchange.microsoft.com',
port: 25,
tls: {
rejectUnauthorized: false
}
})
let mailOptions = {
from: email_username,
to: email_to,
subject: 'Alarm: new high priority issue need to look into!',
html: emailContent,
priority: "high"
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
core.error(error);
} else {
core.info('Email sent: ' + info.response);
}
});
}
module.exports = {
main,
}