-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (62 loc) · 1.73 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
const crypto = require("node:crypto");
// Add more reviewers here
const reviewers = [
"Budhi Widagdo",
"Denny Pradipta",
"Hari Cahya Nugraha",
"Kevin Hermawan",
"Lukman Adisaputro",
"Muslim Ilmiawan",
"Raosan Fikri Lillahi",
"Sinta Herena",
];
(async () => {
// Generate random number
async function rand(min, max) {
return (
(min +
((max - min + 1) * crypto.getRandomValues(new Uint32Array(1))[0]) /
2 ** 32) |
0
);
}
// Create the selected
const selected = [];
const results = {
monika: [],
symon: [],
};
// Select the reviewers
do {
const selectedIndex = await rand(0, 7);
if (!selected.includes(selectedIndex)) {
console.info("Selected", reviewers[selectedIndex]);
selected.push(selectedIndex);
}
} while (selected.length < 4);
// Assign reviewers to projects
for (const index of selected) {
if (results.monika.length < 2) {
console.info("Added", reviewers[index], "as a Monika Reviewer");
results.monika.push(reviewers[index]);
} else {
console.info("Added", reviewers[index], "as a Symon Reviewer");
results.symon.push(reviewers[index]);
}
}
// Create a teams message
fetch(process.env.TEAMS_WEBHOOK_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Monika and Symon Reviewers",
summary: "Here is the assigned reviewers for Monika and Symon today.",
text: `Here is the assigned reviewers for Monika and Symon today:\n\n\n**Monika**: ${results.monika.join(
", "
)}\n\n**Symon**: ${results.symon.join(", ")}\n`,
themeColor: "#309942",
}),
}).then((response) => response.json());
})();