Skip to content

Commit

Permalink
feat: Added color selection
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyhuy committed Sep 12, 2021
1 parent 7fa0d11 commit 07451e1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Specify a custom repository name to overwrite the `username/repo` format.

Hide links on embedded view.

### `color`

Color of the Discord embed.

## :framed_picture: Screenshots

The standard webhook from GitHub to Discord just dumps the commit messages right into your chat, this is fine but sometimes you just want some extra information. Did the commit introduce any new issues? Did it even compile successfully? That's what this Action is for.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
hide_links:
description: Toggle whether to show repo links on the webhook event
default: false
color:
description: Color of the Discord embed
default: '7dbbe6'

runs:
using: 'docker'
Expand Down
10 changes: 6 additions & 4 deletions src/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports.send = (
commits,
size,
hideLinks,
censorUsername
censorUsername,
color
) =>
new Promise((resolve, reject) => {
let client;
Expand All @@ -24,7 +25,7 @@ module.exports.send = (

client
.send(
createEmbed(repo, branch, url, commits, size, hideLinks, censorUsername)
createEmbed(repo, branch, url, commits, size, hideLinks, censorUsername, color)
)
.then(() => {
console.log("Successfully sent the message!");
Expand All @@ -39,14 +40,15 @@ function createEmbed(
commits,
size,
hideLinks,
censorUsername
censorUsername,
color
) {
console.log("Constructing Embed...");
let latest = commits[0];
const count = size == 1 ? "Commit" : " Commits";

let embed = new discord.MessageEmbed()
.setColor('7dbbe6')
.setColor(color)
.setTitle(
`⚡ ${size} ${count} - \`${repo}\` on 🌳 \`${branch}\``
)
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function run() {
const branch = payload.ref.split("/")[payload.ref.split("/").length - 1];
const webhookUrl = core.getInput("webhook_url");
const hideLinks = core.getInput("hide_links");
const color = core.getInput("color");

let repository = payload.repository.full_name;
let id = core.getInput("id");
Expand Down Expand Up @@ -37,7 +38,7 @@ async function run() {
}

webhook
.send(id, token, repository, branch, payload.compare, commits, size, hideLinks, censorUsername)
.send(id, token, repository, branch, payload.compare, commits, size, hideLinks, censorUsername, color)
.catch((err) => core.setFailed(err.message));
}

Expand Down

0 comments on commit 07451e1

Please sign in to comment.