Skip to content

Commit

Permalink
ci: fix release and discord integration [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
JiPaix committed Aug 16, 2021
1 parent 7885058 commit 51714a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
26 changes: 15 additions & 11 deletions build/changelog.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const fs = require('fs')
const axios = require('axios')
const fd = require('form-data')
require('dotenv').config()

const { Client, Intents, MessageEmbed } = require('discord.js');

const version = require('../package.json').version;

let changelog = fs.readFileSync('./CHANGELOG.md').toString().split('---')[0].split(/(?=###)/gm)

changelog.shift()

function createGitHubRelease() {
Expand Down Expand Up @@ -49,34 +51,36 @@ async function uploadAssets(id) {

createGitHubRelease().then(async (res) => {
const remoteFiles = await uploadAssets(res.data.id).catch(e => {throw e})
postToDiscord(remoteFiles)
postToDiscord()
}).catch(e => {
throw e
})

function postToDiscord() {

const discord = new Client({
intents: Intents.NON_PRIVILEGED
intents: Intents.FLAGS.GUILDS
});

const embed = new MessageEmbed()

for (const field of changelog) {
embed.addField(field.split(/\n|\r\n/g)[0].replace('### ', ''), field.replace(/###(.*)(\n|\r\n)/g, '').replace(/\[(.*)]\((.*)\)/g, ''), false)
}

embed

discord.once('ready', async() => {
const embed = new MessageEmbed()
embed
.setTitle('v'+version+' has been released')
.setDescription('CHANGELOG')
.setURL('https://github.com/JiPaix/xdccJS/releases/tag/v'+version)
.setTimestamp(Date.now())
.setColor('DARK_GREEN')
.setThumbnail('https://github.com/JiPaix/xdccJS/raw/main/logo.png')
.setAuthor('JiPaix', 'https://avatars.githubusercontent.com/u/26584973?v=4', 'https://github.com/JiPaix')

discord.once('ready', async() => {
for (const field of changelog) {
embed.addField(field.split(/\n|\r\n/g)[0].replace('### ', ''), field.replace(/###(.*)(\n|\r\n)/g, '').replace(/\[(.*)]\((.*)\)/g, ''), false)
}

console.log(embed)
const chan = await discord.channels.fetch(process.env.DISCORD_CHANNEL_ID)
await chan.send({embed}).catch((e) => {throw e})
await chan.send({embeds: [embed]}).catch((e) => {throw e})
discord.destroy()
});
discord.login(process.env.DISCORD_SECRET);
Expand Down
23 changes: 0 additions & 23 deletions build/changelog.ts

This file was deleted.

18 changes: 17 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"axios": "^0.21.1",
"chai": "^4.2.0",
"discord.js": "^13.1.0",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.0",
Expand Down

0 comments on commit 51714a6

Please sign in to comment.