Skip to content

Commit

Permalink
Refactor discord.js to support message embeds and create Test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Adammatthiesen committed Nov 28, 2024
1 parent b4628aa commit aa78736
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .github/workflows/test_send-discord-hook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: withStudioCMS Test Send Discord Hook

on:
workflow_dispatch:

jobs:
post-message:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: "withstudiocms/automations"
ref: "main"
path: "automation"

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22

- name: Send message on Discord
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_TEST_HOOK }}
DISCORD_MESSAGE: "Test message from GitHub Actions"
DISCORD_EMBEDS: >
[
{
"id": 661098315,
"description": `Just a test message from GitHub Actions.`,
"fields": [],
"author": {
"name": "withStudioCMS Test Bot",
"icon_url": "https://github.com/withstudiocms/studiocms.dev/blob/main/assets/logo-discord.png?raw=true"
},
"title": "Hello, world!",
}
]
run: node automation/scripts/discord.js
4 changes: 3 additions & 1 deletion scripts/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
GITHUB_EVENT_PATH,
DISCORD_WEBHOOK,
DISCORD_MESSAGE,
DISCORD_MESSAGE_EMBEDS,
DISCORD_USERNAME,
DISCORD_AVATAR,
} = process.env;
Expand All @@ -16,7 +17,8 @@ if (!GITHUB_ACTION || !DISCORD_WEBHOOK) {
}

const body = {
content: DISCORD_MESSAGE,
content: DISCORD_MESSAGE ? DISCORD_MESSAGE : '',
embeds: DISCORD_MESSAGE_EMBEDS ? JSON.parse(DISCORD_MESSAGE_EMBEDS) : [],
};
if (DISCORD_USERNAME) {
body.username = DISCORD_USERNAME;
Expand Down

0 comments on commit aa78736

Please sign in to comment.