Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dennypradipta committed May 14, 2024
0 parents commit 02bdaca
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/run-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run Node.js script daily

on:
schedule:
# Runs at 00:00 UTC every day
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
run-script:
runs-on: ubuntu-latest

env:
TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Run script
run: node index.js
68 changes: 68 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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());
})();
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "reviewer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

0 comments on commit 02bdaca

Please sign in to comment.