-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: discord bot for releases note (#3306)
- Loading branch information
1 parent
5b1f36d
commit 8b770e9
Showing
2 changed files
with
60 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,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; | ||
|
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,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}) |