Skip to content

Commit

Permalink
Update README. Change sender icon. Add week days to embed description…
Browse files Browse the repository at this point in the history
…. Finally, the selection of scrum masters is now partly random: 1 scrum master is determined from the action run number, and the second from a random number.
  • Loading branch information
Daniel-Runge committed Sep 27, 2021
1 parent 01c2b9a commit 7ece6d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ Github action to determine a team's scrummasters and post it in the team discord

## parameters

team should be a JSON string with an array of strings, with minimum 2 members.
team: a JSON string with and array of string of team member names (minimum 2).
webhook: a discord webhook in the form of an URL.
> :warning: **Warning:** You should keep the webhook as a github secret.
webhook should be a discord webhook in the form of an URL.

### examples

team: "["Octo", "Cat"]"
## examples

team: "["Octo", "Cat"]"
webhook: https://discord.com/api/webhooks/32192256368640/aagaxz2cWHb-RfO0iO3fXJKrvMUaY11dsupZHr9_vYCJXs7n5GSpEn
30 changes: 22 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const Discord = require("discord.js");
const core = require("@actions/core");

const ICON_URL =
const AAU_ICON =
"https://media-exp1.licdn.com/dms/image/C510BAQHgfIxjqWSSsQ/company-logo_200_200/0/1519855922416?e=2159024400&v=beta&t=_L2XLMCXeEzSX_c8oBMM_uuEK1kgfno7ViFJXD5BP6U";
const GITHUB_ICON = "https://avatars.githubusercontent.com/u/86346038?s=200&v=4";

try {
const team = JSON.parse(core.getInput("team"));
Expand All @@ -17,23 +18,25 @@ try {
function determineScrumMasters(team) {
if (team.length < 2) throw new Error("You need a larger team");

const number = process.env.GITHUB_RUN_NUMBER;
const variance = process.env.GITHUB_RUN_ID;
const scrumMasterOne = team.splice(number % team.length, 1);
const first = process.env.GITHUB_RUN_NUMBER % team.length;
const second = Math.random() * team.length - 1;
const scrumMasterOne = team.splice(first, 1);

if (team.length < 4) return scrumMasterOne;

const scrumMasterTwo = team.splice((number + variance) % team.length, 1);
const scrumMasterTwo = team.splice(second, 1);

return scrumMasterOne.concat(scrumMasterTwo);
}

function buildEmbed(scrumMasters) {
const week = getWeekStartAndEnd();
let result = new Discord.MessageEmbed()
.setTitle("New Scrum Master(s)")
.setDescription(`The scrum masters for ${week.start} to ${week.end}`)
.setColor("#211a52")
.setAuthor("AAU-Dat", ICON_URL, "http://github.com/AAU-Dat")
.setFooter("Generated by a Github Action")
.setAuthor("AAU-Dat", AAU_ICON, "http://github.com/AAU-Dat")
.setFooter("Generated by the scrummasters github action.")
.addField("Scrum master", scrumMasters[0], true);

if (scrumMasters.length > 1) {
Expand All @@ -52,7 +55,7 @@ function postScrumMastersDiscord(embed) {
webhookClient
.send({
username: "Github Action",
avatarURL: ICON_URL,
avatarURL: GITHUB_ICON,
embeds: [embed],
})
.catch(console.error);
Expand All @@ -69,3 +72,14 @@ function breakWebhook(webhook) {
}
return { id: array[length - 2], token: array[length - 1] };
}

function getWeekStartAndEnd(){
const today = new Date();
const weekend = new Date();
weekend.setDate(weekend.getDate() + 6);
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
const todayString = today.toDateString();
const weekendString = weekend.toDateString();

return {start: todayString, end: weekendString}
}

0 comments on commit 7ece6d6

Please sign in to comment.