From 02bdacaa4100018a4b007bc4d39c12fd9ea90d0b Mon Sep 17 00:00:00 2001 From: Denny Pradipta Date: Tue, 14 May 2024 10:45:49 +0700 Subject: [PATCH] Initial commit --- .github/workflows/run-script.yml | 26 ++++++++++++ index.js | 68 ++++++++++++++++++++++++++++++++ package.json | 11 ++++++ 3 files changed, 105 insertions(+) create mode 100644 .github/workflows/run-script.yml create mode 100644 index.js create mode 100644 package.json diff --git a/.github/workflows/run-script.yml b/.github/workflows/run-script.yml new file mode 100644 index 0000000..604d250 --- /dev/null +++ b/.github/workflows/run-script.yml @@ -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 diff --git a/index.js b/index.js new file mode 100644 index 0000000..250aa5f --- /dev/null +++ b/index.js @@ -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()); +})(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..1ab1567 --- /dev/null +++ b/package.json @@ -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" +}