-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
109 lines (103 loc) · 3.11 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
var fs = require("fs");
const context = JSON.parse(process.env.GITHUB_CONTEXT);
const submitter = context.actor;
const submissionDate = context.event.issue.created_at;
const template_fields = context.event.issue.body.split("### ").slice(1);
const addChainPR = (fields) => {
const chainId = fields[0].split("\n\n")[1].toLowerCase();
const note = fields[1].split("\n\n").slice(1, -1).join("\r\n");
const threatLevel = fields[2].split("\n\n")[1][0];
const blacklist = JSON.parse(fs.readFileSync("chain-blacklist.json", "utf8"));
const exists = blacklist.find((x) => x.chainId == chainId);
if (exists >= 0) {
blacklist[exists].userNotes.push({
userName: submitter,
userNote: note,
noteDate: submissionDate,
});
} else {
blacklist.push({
chainId,
submissionDate,
threatLevel,
userNotes: [
{
userName: submitter,
userNote: note,
noteDate: submissionDate,
},
],
});
}
fs.writeFileSync("chain-blacklist.json", JSON.stringify(blacklist, null, 2));
};
const addAssetPR = (fields) => {
const baseDenom = fields[0].split("\n\n")[1].toLowerCase();
const chainId = fields[1].split("\n\n")[1].toLowerCase();
const note = fields[2].split("\n\n").slice(1, -1).join("\r\n");
const threatLevel = fields[3].split("\n\n")[1][0];
const blacklist = JSON.parse(fs.readFileSync("asset-blacklist.json", "utf8"));
const denom_index = blacklist.find(
(x) => x.baseDenom == denom && x.chainId == chainId
);
if (denom_index >= 0) {
blacklist[denom_index].userNotes.push({
userName: submitter,
userNote: note,
noteDate: submissionDate,
});
} else {
blacklist.push({
baseDenom,
chainId,
submissionDate,
threatLevel,
userNotes: [
{
userName: submitter,
userNote: note,
noteDate: submissionDate,
},
],
});
}
fs.writeFileSync("asset-blacklist.json", JSON.stringify(blacklist, null, 2));
};
const addSitePR = (fields) => {
const urlObj = new URL(fields[0].split("\n\n")[1]);
const url = (urlObj.host + urlObj.pathname).toLowerCase();
const note = fields[1].split("\n\n").slice(1, -1).join("\r\n");
const threatLevel = fields[2].split("\n\n")[1][0];
const blacklist = JSON.parse(fs.readFileSync("site-blacklist.json", "utf8"));
const exists = blacklist.find((x) => x.url == url);
if (exists >= 0) {
blacklist[exists].userNotes.push({
userName: submitter,
userNote: note,
noteDate: submissionDate,
});
} else {
blacklist.push({
url,
submissionDate,
threatLevel,
userNotes: [
{
userName: submitter,
userNote: note,
noteDate: submissionDate,
},
],
});
}
fs.writeFileSync("site-blacklist.json", JSON.stringify(blacklist, null, 2));
};
if (context.event.issue.title.startsWith("[Chain-add]: ")) {
addChainPR(template_fields);
}
if (context.event.issue.title.startsWith("[Site-add]: ")) {
addSitePR(template_fields);
}
if (context.event.issue.title.startsWith("[Asset-add]: ")) {
addAssetPR(template_fields);
}