-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 02bdaca
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |