Skip to content

Commit

Permalink
chore: discord bot for releases note (#3306)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Sep 29, 2023
1 parent 5b1f36d commit 8b770e9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/bot-scripts/post-release-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference path="types.d.ts" />
// @ts-check

/**
* @param {{github: Github, context: Context}} param
*/
async function main(param) {
const { github, context } = param;

const discordWebhookUrl = process.env.DISCORD_WEBHOOK_URL || '';

// remove multiple spaces and put links between < > to prevent embeds
const releaseNotes = context.payload.release.body.replace(/(\r\n+|\n+|\r+)/gm, '\n').replace(/(https:\/\/[^)]+)/g, '<$1>');

try {
console.log('Posting release notes to Discord...');
console.log(releaseNotes);

const response = await fetch(discordWebhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ content: releaseNotes }),
});

if (response.ok) {
console.log('Release notes posted to Discord successfully.');
} else {
console.error('Failed to post release notes to Discord:', response.status, response.statusText);
}
} catch (error) {
console.error('Error posting release notes to Discord:', error);
}
}
module.exports = main;

23 changes: 23 additions & 0 deletions .github/workflows/discord-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Post Release Notes to Discord

on:
release:
types:
- published

jobs:
post-release-notes:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- uses: actions/github-script@v6
name: Post release notes to Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
with:
script: |
const script = require('./.github/bot-scripts/post-release-notes.js')
script({github, context})

0 comments on commit 8b770e9

Please sign in to comment.