From 8fbd9735534b8a627aa3111e1ba02a309209955b Mon Sep 17 00:00:00 2001 From: filipkule Date: Wed, 14 Oct 2020 21:00:53 +0200 Subject: [PATCH 01/20] Create test.yml --- .github/workflows/test.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5b1a880 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,14 @@ +name: Discord Webhook Messages +on: + push: + branches: ['master'] +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run Discord Webhook + uses: bythope/discord-webhook-messages@v1.0.0 + with: + webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} + handler: 'release' From 59a2b882fd2b9b8329f1610169d781d0a4c2768b Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 21:15:42 +0200 Subject: [PATCH 02/20] Inital commit for push handler --- .github/workflows/test.yml | 4 ++-- src/handlers/pushHandler.js | 44 +++++++++++++++++++++++++++++++++++++ src/index.js | 2 ++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/handlers/pushHandler.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b1a880..f189fc6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Run Discord Webhook - uses: bythope/discord-webhook-messages@v1.0.0 + uses: filipkule/discord-webhook-messages@master with: webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} - handler: 'release' + handler: 'push' diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js new file mode 100644 index 0000000..c20b63c --- /dev/null +++ b/src/handlers/pushHandler.js @@ -0,0 +1,44 @@ +const core = require('@actions/core') +const github = require('@actions/github') +const { WebhookClient, MessageEmbed } = require('discord.js') +const { extractDataFromWebhookUrl } = require('../helpers') + +module.exports = ({ webhookUrl }) => { + const { payload, eventName } = github.context + + // if (eventName !== 'push') { + // console.warn('push handler can be executed only on "push" action triggers') + // return Promise.resolve() + // } + + // const { id, token } = extractDataFromWebhookUrl(webhookUrl) + // const client = new WebhookClient(id, token) + + // let embed = createEmbed(data) + // return client.send(embed).then(result => { + // client.destroy() + // return data + // }).catch(error => { + // client.destroy() + // throw error + // }) + console.log(JSON.stringify(payload), eventName) + return Promise.resolve() +} + + +function createEmbed({ action, name, body, tag, url, draft, prerelease, published, branch }) { + let embed = new MessageEmbed({ type: 'rich' }) + embed.setColor(prerelease ? 0xf66a0a : 0x28a745) + embed.setTitle(`${prerelease ? 'Pre-release' : 'Release'}: ${tag} ${name} ${draft ? '(Draft)': ''}`) + embed.setURL(url) + embed.setDescription(`${trimBody(body)}`) + embed.setFooter(`Branch: ${branch}`) + embed.setTimestamp(new Date(published)) + return embed +} + +function trimBody(body = '') { + if (body.length < 2000) return body + return `${body.substring(0, 2000)}...` +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 945fef5..0edc1ff 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ const core = require('@actions/core') const { isWebhookUrl } = require('./helpers') const HandlerExecutor = require('./HandlerExecutor') const releaseHandler = require('./handlers/releaseHandler') +const pushHandler = require('./handlers/pushHandler') @@ -12,6 +13,7 @@ const input = { const handlerExecutor = new HandlerExecutor(input) handlerExecutor.add('release', releaseHandler) +handlerExecutor.add('push', pushHandler) if (!isWebhookUrl(input.webhookUrl)) { core.setFailed('The given webhook url is not valid. Please ensure you give a full discord webhook url') From 9605d9959f92552451c9ad12721d883d01607d36 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 21:18:25 +0200 Subject: [PATCH 03/20] Built the project --- dist/index.js | 294 +++++++++++++++++++++++++++++--------------------- 1 file changed, 173 insertions(+), 121 deletions(-) diff --git a/dist/index.js b/dist/index.js index b19c379..2b9cc62 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36366,96 +36366,146 @@ function socketOnError() { /***/ 5523: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -const core = __webpack_require__(2186) - -class HandlerExecutor { - - constructor(input) { - this.handlers = {} - this.input = input - } - - add(key, handler) { - if (typeof this.handlers[key] === 'function') { - console.error(`Handler ${key} already exists!`) - } - if (typeof handler !== 'function') { - console.error(`Handler ${key} can not be added. handler must be a function`) - } - this.handlers[key] = handler - } - - execute(key) { - if (typeof this.handlers[key] !== 'function') { - core.setFailed(`Handler of type ${key} is not supported, available handlers: ${Object.keys(this.handlers).join(', ')}`) - return - } - const promise = this.handlers[key](this.input) - if (typeof promise.then !== 'function') { - console.error(`Handler ${key} must return promise!`) - return - } - - promise.then(result => { - core.setOutput('data', result) - }).catch(error => { - core.setFailed(`Handler ${key} failed. Reason: ${error.message}`) - console.error(error) - }) - } - -} - +const core = __webpack_require__(2186) + +class HandlerExecutor { + + constructor(input) { + this.handlers = {} + this.input = input + } + + add(key, handler) { + if (typeof this.handlers[key] === 'function') { + console.error(`Handler ${key} already exists!`) + } + if (typeof handler !== 'function') { + console.error(`Handler ${key} can not be added. handler must be a function`) + } + this.handlers[key] = handler + } + + execute(key) { + if (typeof this.handlers[key] !== 'function') { + core.setFailed(`Handler of type ${key} is not supported, available handlers: ${Object.keys(this.handlers).join(', ')}`) + return + } + const promise = this.handlers[key](this.input) + if (typeof promise.then !== 'function') { + console.error(`Handler ${key} must return promise!`) + return + } + + promise.then(result => { + core.setOutput('data', result) + }).catch(error => { + core.setFailed(`Handler ${key} failed. Reason: ${error.message}`) + console.error(error) + }) + } + +} + module.exports = HandlerExecutor /***/ }), -/***/ 285: +/***/ 5172: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { -const core = __webpack_require__(2186) -const github = __webpack_require__(5438) -const { WebhookClient, MessageEmbed } = __webpack_require__(5973) -const { extractDataFromWebhookUrl } = __webpack_require__(8505) - -module.exports = ({ webhookUrl }) => { - const { payload, eventName } = github.context - - if (eventName !== 'release') { - console.warn('release handler can be executed only on "release" action triggers') - return Promise.resolve() - } - const { action, release: { body, draft, html_url, name, prerelease, published_at, tag_name, target_commitish, } } = payload - const data = { action, name, body, tag: tag_name, url: html_url, draft, prerelease, published: published_at, branch: target_commitish } - - const { id, token } = extractDataFromWebhookUrl(webhookUrl) - const client = new WebhookClient(id, token) - - let embed = createEmbed(data) - return client.send(embed).then(result => { - client.destroy() - return data - }).catch(error => { - client.destroy() - throw error - }) +const core = __webpack_require__(2186) +const github = __webpack_require__(5438) +const { WebhookClient, MessageEmbed } = __webpack_require__(5973) +const { extractDataFromWebhookUrl } = __webpack_require__(8505) + +module.exports = ({ webhookUrl }) => { + const { payload, eventName } = github.context + + // if (eventName !== 'push') { + // console.warn('push handler can be executed only on "push" action triggers') + // return Promise.resolve() + // } + + // const { id, token } = extractDataFromWebhookUrl(webhookUrl) + // const client = new WebhookClient(id, token) + + // let embed = createEmbed(data) + // return client.send(embed).then(result => { + // client.destroy() + // return data + // }).catch(error => { + // client.destroy() + // throw error + // }) + console.log(JSON.stringify(payload), eventName) + return Promise.resolve() +} + + +function createEmbed({ action, name, body, tag, url, draft, prerelease, published, branch }) { + let embed = new MessageEmbed({ type: 'rich' }) + embed.setColor(prerelease ? 0xf66a0a : 0x28a745) + embed.setTitle(`${prerelease ? 'Pre-release' : 'Release'}: ${tag} ${name} ${draft ? '(Draft)': ''}`) + embed.setURL(url) + embed.setDescription(`${trimBody(body)}`) + embed.setFooter(`Branch: ${branch}`) + embed.setTimestamp(new Date(published)) + return embed +} + +function trimBody(body = '') { + if (body.length < 2000) return body + return `${body.substring(0, 2000)}...` } +/***/ }), -function createEmbed({ action, name, body, tag, url, draft, prerelease, published, branch }) { - let embed = new MessageEmbed({ type: 'rich' }) - embed.setColor(prerelease ? 0xf66a0a : 0x28a745) - embed.setTitle(`${prerelease ? 'Pre-release' : 'Release'}: ${tag} ${name} ${draft ? '(Draft)': ''}`) - embed.setURL(url) - embed.setDescription(`${trimBody(body)}`) - embed.setFooter(`Branch: ${branch}`) - embed.setTimestamp(new Date(published)) - return embed -} +/***/ 285: +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { -function trimBody(body = '') { - if (body.length < 2000) return body - return `${body.substring(0, 2000)}...` +const core = __webpack_require__(2186) +const github = __webpack_require__(5438) +const { WebhookClient, MessageEmbed } = __webpack_require__(5973) +const { extractDataFromWebhookUrl } = __webpack_require__(8505) + +module.exports = ({ webhookUrl }) => { + const { payload, eventName } = github.context + + if (eventName !== 'release') { + console.warn('release handler can be executed only on "release" action triggers') + return Promise.resolve() + } + const { action, release: { body, draft, html_url, name, prerelease, published_at, tag_name, target_commitish, } } = payload + const data = { action, name, body, tag: tag_name, url: html_url, draft, prerelease, published: published_at, branch: target_commitish } + + const { id, token } = extractDataFromWebhookUrl(webhookUrl) + const client = new WebhookClient(id, token) + + let embed = createEmbed(data) + return client.send(embed).then(result => { + client.destroy() + return data + }).catch(error => { + client.destroy() + throw error + }) +} + + +function createEmbed({ action, name, body, tag, url, draft, prerelease, published, branch }) { + let embed = new MessageEmbed({ type: 'rich' }) + embed.setColor(prerelease ? 0xf66a0a : 0x28a745) + embed.setTitle(`${prerelease ? 'Pre-release' : 'Release'}: ${tag} ${name} ${draft ? '(Draft)': ''}`) + embed.setURL(url) + embed.setDescription(`${trimBody(body)}`) + embed.setFooter(`Branch: ${branch}`) + embed.setTimestamp(new Date(published)) + return embed +} + +function trimBody(body = '') { + if (body.length < 2000) return body + return `${body.substring(0, 2000)}...` } /***/ }), @@ -36463,27 +36513,27 @@ function trimBody(body = '') { /***/ 8505: /***/ ((__unused_webpack_module, exports) => { -const isWebhookUrl = url => { - let regExp = new RegExp(/https:\/\/discord(app|)\.com\/api\/webhooks\/\d+?\/.+/i) - return regExp.exec(url) -} - -const extractDataFromWebhookUrl = (url = "") => { - if (isWebhookUrl(url)) { - let regExp = new RegExp(/discordapp.com\/api\/webhooks\/([^\/]+)\/([^\/]+)/) - let [ _, id, token ] = url.match(regExp) - return { id, token } - } else { - return null - } -} - -const interpolate = (string, object) => { - return string -} - -exports.isWebhookUrl = isWebhookUrl -exports.extractDataFromWebhookUrl = extractDataFromWebhookUrl +const isWebhookUrl = url => { + let regExp = new RegExp(/https:\/\/discord(app|)\.com\/api\/webhooks\/\d+?\/.+/i) + return regExp.exec(url) +} + +const extractDataFromWebhookUrl = (url = "") => { + if (isWebhookUrl(url)) { + let regExp = new RegExp(/discordapp.com\/api\/webhooks\/([^\/]+)\/([^\/]+)/) + let [ _, id, token ] = url.match(regExp) + return { id, token } + } else { + return null + } +} + +const interpolate = (string, object) => { + return string +} + +exports.isWebhookUrl = isWebhookUrl +exports.extractDataFromWebhookUrl = extractDataFromWebhookUrl exports.interpolate = interpolate /***/ }), @@ -36491,25 +36541,27 @@ exports.interpolate = interpolate /***/ 4351: /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { -const core = __webpack_require__(2186) -const { isWebhookUrl } = __webpack_require__(8505) -const HandlerExecutor = __webpack_require__(5523) -const releaseHandler = __webpack_require__(285) - - - -const input = { - webhookUrl: core.getInput('webhookUrl'), - handler: core.getInput('handler') -} - -const handlerExecutor = new HandlerExecutor(input) -handlerExecutor.add('release', releaseHandler) - -if (!isWebhookUrl(input.webhookUrl)) { - core.setFailed('The given webhook url is not valid. Please ensure you give a full discord webhook url') -} - +const core = __webpack_require__(2186) +const { isWebhookUrl } = __webpack_require__(8505) +const HandlerExecutor = __webpack_require__(5523) +const releaseHandler = __webpack_require__(285) +const pushHandler = __webpack_require__(5172) + + + +const input = { + webhookUrl: core.getInput('webhookUrl'), + handler: core.getInput('handler') +} + +const handlerExecutor = new HandlerExecutor(input) +handlerExecutor.add('release', releaseHandler) +handlerExecutor.add('push', pushHandler) + +if (!isWebhookUrl(input.webhookUrl)) { + core.setFailed('The given webhook url is not valid. Please ensure you give a full discord webhook url') +} + handlerExecutor.execute(input.handler) /***/ }), @@ -36566,7 +36618,7 @@ module.exports = eval("require")("zlib-sync"); /***/ ((module) => { "use strict"; -module.exports = JSON.parse("{\"_from\":\"discord.js\",\"_id\":\"discord.js@12.3.1\",\"_inBundle\":false,\"_integrity\":\"sha512-mSFyV/mbvzH12UXdS4zadmeUf8IMQOo/YdunubG1wWt1xjWvtaJz/s9CGsFD2B5pTw1W/LXxxUbrQjIZ/xlUdw==\",\"_location\":\"/discord.js\",\"_phantomChildren\":{},\"_requested\":{\"type\":\"tag\",\"registry\":true,\"raw\":\"discord.js\",\"name\":\"discord.js\",\"escapedName\":\"discord.js\",\"rawSpec\":\"\",\"saveSpec\":null,\"fetchSpec\":\"latest\"},\"_requiredBy\":[\"#USER\",\"/\"],\"_resolved\":\"https://registry.npmjs.org/discord.js/-/discord.js-12.3.1.tgz\",\"_shasum\":\"8f58ac17d29b068dbfeb6c01fc7777bacd5324cf\",\"_spec\":\"discord.js\",\"_where\":\"/home/kalevski/projects/bythope/discord-webhook\",\"author\":{\"name\":\"Amish Shah\",\"email\":\"amishshah.2k@gmail.com\"},\"browser\":{\"@discordjs/opus\":false,\"https\":false,\"ws\":false,\"erlpack\":false,\"prism-media\":false,\"opusscript\":false,\"node-opus\":false,\"tweetnacl\":false,\"sodium\":false,\"worker_threads\":false,\"zlib-sync\":false,\"src/sharding/Shard.js\":false,\"src/sharding/ShardClientUtil.js\":false,\"src/sharding/ShardingManager.js\":false,\"src/client/voice/ClientVoiceManager.js\":false,\"src/client/voice/VoiceBroadcast.js\":false,\"src/client/voice/VoiceConnection.js\":false,\"src/client/voice/dispatcher/BroadcastDispatcher.js\":false,\"src/client/voice/dispatcher/StreamDispatcher.js\":false,\"src/client/voice/networking/VoiceUDPClient.js\":false,\"src/client/voice/networking/VoiceWebSocket.js\":false,\"src/client/voice/player/AudioPlayer.js\":false,\"src/client/voice/player/BasePlayer.js\":false,\"src/client/voice/player/BroadcastAudioPlayer.js\":false,\"src/client/voice/receiver/PacketHandler.js\":false,\"src/client/voice/receiver/Receiver.js\":false,\"src/client/voice/util/PlayInterface.js\":false,\"src/client/voice/util/Secretbox.js\":false,\"src/client/voice/util/Silence.js\":false,\"src/client/voice/util/VolumeInterface.js\":false},\"bugs\":{\"url\":\"https://github.com/discordjs/discord.js/issues\"},\"bundleDependencies\":false,\"commitlint\":{\"extends\":[\"@commitlint/config-angular\"],\"rules\":{\"scope-case\":[2,\"always\",\"pascal-case\"],\"type-enum\":[2,\"always\",[\"chore\",\"build\",\"ci\",\"docs\",\"feat\",\"fix\",\"perf\",\"refactor\",\"revert\",\"style\",\"test\"]]}},\"dependencies\":{\"@discordjs/collection\":\"^0.1.6\",\"@discordjs/form-data\":\"^3.0.1\",\"abort-controller\":\"^3.0.0\",\"node-fetch\":\"^2.6.0\",\"prism-media\":\"^1.2.2\",\"setimmediate\":\"^1.0.5\",\"tweetnacl\":\"^1.0.3\",\"ws\":\"^7.3.1\"},\"deprecated\":false,\"description\":\"A powerful library for interacting with the Discord API\",\"devDependencies\":{\"@commitlint/cli\":\"^9.1.2\",\"@commitlint/config-angular\":\"^9.1.1\",\"@types/node\":\"^12.12.6\",\"@types/ws\":\"^7.2.6\",\"cross-env\":\"^7.0.2\",\"discord.js-docgen\":\"github:discordjs/docgen\",\"dtslint\":\"^3.6.14\",\"eslint\":\"^7.6.0\",\"eslint-config-prettier\":\"^6.11.0\",\"eslint-plugin-import\":\"^2.22.0\",\"eslint-plugin-prettier\":\"^3.1.4\",\"husky\":\"^4.2.5\",\"jest\":\"^26.4.0\",\"json-filter-loader\":\"^1.0.0\",\"lint-staged\":\"^10.2.11\",\"prettier\":\"^2.0.5\",\"terser-webpack-plugin\":\"^4.1.0\",\"tslint\":\"^6.1.3\",\"typescript\":\"^3.9.7\",\"webpack\":\"^4.44.1\",\"webpack-cli\":\"^3.3.12\"},\"engines\":{\"node\":\">=12.0.0\"},\"exports\":{\".\":[{\"require\":\"./src/index.js\",\"import\":\"./esm/discord.mjs\"},\"./src/index.js\"],\"./esm\":\"./esm/discord.mjs\"},\"homepage\":\"https://github.com/discordjs/discord.js#readme\",\"husky\":{\"hooks\":{\"pre-commit\":\"lint-staged\",\"commit-msg\":\"commitlint -E HUSKY_GIT_PARAMS\"}},\"keywords\":[\"discord\",\"api\",\"bot\",\"client\",\"node\",\"discordapp\"],\"license\":\"Apache-2.0\",\"lint-staged\":{\"*.js\":\"eslint --fix\",\"*.ts\":\"prettier --write --single-quote --print-width 120 --trailing-comma all --end-of-line lf --arrow-parens avoid\"},\"main\":\"./src/index\",\"name\":\"discord.js\",\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/discordjs/discord.js.git\"},\"runkitExampleFilename\":\"./docs/examples/ping.js\",\"scripts\":{\"build:browser\":\"webpack\",\"docs\":\"docgen --source src --custom docs/index.yml --output docs/docs.json\",\"docs:test\":\"docgen --source src --custom docs/index.yml\",\"lint\":\"eslint src\",\"lint:fix\":\"eslint src --fix\",\"lint:typings\":\"tslint typings/index.d.ts\",\"prepublishOnly\":\"npm run test && cross-env NODE_ENV=production npm run build:browser\",\"prettier\":\"prettier --write --single-quote --print-width 120 --trailing-comma all --end-of-line lf --arrow-parens avoid src/**/*.js typings/**/*.ts\",\"test\":\"npm run lint && npm run docs:test && npm run lint:typings\",\"test:typescript\":\"tsc\"},\"types\":\"./typings/index.d.ts\",\"unpkg\":\"./webpack/discord.min.js\",\"version\":\"12.3.1\"}"); +module.exports = JSON.parse("{\"_args\":[[\"discord.js@12.3.1\",\"D:\\\\filip\\\\programiranje\\\\Repo\\\\discord-webhook-messages\"]],\"_from\":\"discord.js@12.3.1\",\"_id\":\"discord.js@12.3.1\",\"_inBundle\":false,\"_integrity\":\"sha512-mSFyV/mbvzH12UXdS4zadmeUf8IMQOo/YdunubG1wWt1xjWvtaJz/s9CGsFD2B5pTw1W/LXxxUbrQjIZ/xlUdw==\",\"_location\":\"/discord.js\",\"_phantomChildren\":{},\"_requested\":{\"type\":\"version\",\"registry\":true,\"raw\":\"discord.js@12.3.1\",\"name\":\"discord.js\",\"escapedName\":\"discord.js\",\"rawSpec\":\"12.3.1\",\"saveSpec\":null,\"fetchSpec\":\"12.3.1\"},\"_requiredBy\":[\"/\"],\"_resolved\":\"https://registry.npmjs.org/discord.js/-/discord.js-12.3.1.tgz\",\"_spec\":\"12.3.1\",\"_where\":\"D:\\\\filip\\\\programiranje\\\\Repo\\\\discord-webhook-messages\",\"author\":{\"name\":\"Amish Shah\",\"email\":\"amishshah.2k@gmail.com\"},\"browser\":{\"@discordjs/opus\":false,\"https\":false,\"ws\":false,\"erlpack\":false,\"prism-media\":false,\"opusscript\":false,\"node-opus\":false,\"tweetnacl\":false,\"sodium\":false,\"worker_threads\":false,\"zlib-sync\":false,\"src/sharding/Shard.js\":false,\"src/sharding/ShardClientUtil.js\":false,\"src/sharding/ShardingManager.js\":false,\"src/client/voice/ClientVoiceManager.js\":false,\"src/client/voice/VoiceBroadcast.js\":false,\"src/client/voice/VoiceConnection.js\":false,\"src/client/voice/dispatcher/BroadcastDispatcher.js\":false,\"src/client/voice/dispatcher/StreamDispatcher.js\":false,\"src/client/voice/networking/VoiceUDPClient.js\":false,\"src/client/voice/networking/VoiceWebSocket.js\":false,\"src/client/voice/player/AudioPlayer.js\":false,\"src/client/voice/player/BasePlayer.js\":false,\"src/client/voice/player/BroadcastAudioPlayer.js\":false,\"src/client/voice/receiver/PacketHandler.js\":false,\"src/client/voice/receiver/Receiver.js\":false,\"src/client/voice/util/PlayInterface.js\":false,\"src/client/voice/util/Secretbox.js\":false,\"src/client/voice/util/Silence.js\":false,\"src/client/voice/util/VolumeInterface.js\":false},\"bugs\":{\"url\":\"https://github.com/discordjs/discord.js/issues\"},\"commitlint\":{\"extends\":[\"@commitlint/config-angular\"],\"rules\":{\"scope-case\":[2,\"always\",\"pascal-case\"],\"type-enum\":[2,\"always\",[\"chore\",\"build\",\"ci\",\"docs\",\"feat\",\"fix\",\"perf\",\"refactor\",\"revert\",\"style\",\"test\"]]}},\"dependencies\":{\"@discordjs/collection\":\"^0.1.6\",\"@discordjs/form-data\":\"^3.0.1\",\"abort-controller\":\"^3.0.0\",\"node-fetch\":\"^2.6.0\",\"prism-media\":\"^1.2.2\",\"setimmediate\":\"^1.0.5\",\"tweetnacl\":\"^1.0.3\",\"ws\":\"^7.3.1\"},\"description\":\"A powerful library for interacting with the Discord API\",\"devDependencies\":{\"@commitlint/cli\":\"^9.1.2\",\"@commitlint/config-angular\":\"^9.1.1\",\"@types/node\":\"^12.12.6\",\"@types/ws\":\"^7.2.6\",\"cross-env\":\"^7.0.2\",\"discord.js-docgen\":\"github:discordjs/docgen\",\"dtslint\":\"^3.6.14\",\"eslint\":\"^7.6.0\",\"eslint-config-prettier\":\"^6.11.0\",\"eslint-plugin-import\":\"^2.22.0\",\"eslint-plugin-prettier\":\"^3.1.4\",\"husky\":\"^4.2.5\",\"jest\":\"^26.4.0\",\"json-filter-loader\":\"^1.0.0\",\"lint-staged\":\"^10.2.11\",\"prettier\":\"^2.0.5\",\"terser-webpack-plugin\":\"^4.1.0\",\"tslint\":\"^6.1.3\",\"typescript\":\"^3.9.7\",\"webpack\":\"^4.44.1\",\"webpack-cli\":\"^3.3.12\"},\"engines\":{\"node\":\">=12.0.0\"},\"exports\":{\".\":[{\"require\":\"./src/index.js\",\"import\":\"./esm/discord.mjs\"},\"./src/index.js\"],\"./esm\":\"./esm/discord.mjs\"},\"homepage\":\"https://github.com/discordjs/discord.js#readme\",\"husky\":{\"hooks\":{\"pre-commit\":\"lint-staged\",\"commit-msg\":\"commitlint -E HUSKY_GIT_PARAMS\"}},\"keywords\":[\"discord\",\"api\",\"bot\",\"client\",\"node\",\"discordapp\"],\"license\":\"Apache-2.0\",\"lint-staged\":{\"*.js\":\"eslint --fix\",\"*.ts\":\"prettier --write --single-quote --print-width 120 --trailing-comma all --end-of-line lf --arrow-parens avoid\"},\"main\":\"./src/index\",\"name\":\"discord.js\",\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/discordjs/discord.js.git\"},\"runkitExampleFilename\":\"./docs/examples/ping.js\",\"scripts\":{\"build:browser\":\"webpack\",\"docs\":\"docgen --source src --custom docs/index.yml --output docs/docs.json\",\"docs:test\":\"docgen --source src --custom docs/index.yml\",\"lint\":\"eslint src\",\"lint:fix\":\"eslint src --fix\",\"lint:typings\":\"tslint typings/index.d.ts\",\"prepublishOnly\":\"npm run test && cross-env NODE_ENV=production npm run build:browser\",\"prettier\":\"prettier --write --single-quote --print-width 120 --trailing-comma all --end-of-line lf --arrow-parens avoid src/**/*.js typings/**/*.ts\",\"test\":\"npm run lint && npm run docs:test && npm run lint:typings\",\"test:typescript\":\"tsc\"},\"types\":\"./typings/index.d.ts\",\"unpkg\":\"./webpack/discord.min.js\",\"version\":\"12.3.1\"}"); /***/ }), From 67bb61b800ed03eeb2927cf8e88dae14d30ffea8 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 21:22:48 +0200 Subject: [PATCH 04/20] Trying to send Hello message --- dist/index.js | 19 +++++++++---------- src/handlers/pushHandler.js | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2b9cc62..e9741a2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36426,17 +36426,16 @@ module.exports = ({ webhookUrl }) => { // return Promise.resolve() // } - // const { id, token } = extractDataFromWebhookUrl(webhookUrl) - // const client = new WebhookClient(id, token) + const { id, token } = extractDataFromWebhookUrl(webhookUrl) + const client = new WebhookClient(id, token) - // let embed = createEmbed(data) - // return client.send(embed).then(result => { - // client.destroy() - // return data - // }).catch(error => { - // client.destroy() - // throw error - // }) + return client.send('Hello').then(result => { + client.destroy() + return '' + }).catch(error => { + client.destroy() + throw error + }) console.log(JSON.stringify(payload), eventName) return Promise.resolve() } diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index c20b63c..ad9ed78 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -11,17 +11,16 @@ module.exports = ({ webhookUrl }) => { // return Promise.resolve() // } - // const { id, token } = extractDataFromWebhookUrl(webhookUrl) - // const client = new WebhookClient(id, token) + const { id, token } = extractDataFromWebhookUrl(webhookUrl) + const client = new WebhookClient(id, token) - // let embed = createEmbed(data) - // return client.send(embed).then(result => { - // client.destroy() - // return data - // }).catch(error => { - // client.destroy() - // throw error - // }) + return client.send('Hello').then(result => { + client.destroy() + return '' + }).catch(error => { + client.destroy() + throw error + }) console.log(JSON.stringify(payload), eventName) return Promise.resolve() } From 05dafecfdc3e5d39107ddc005347531feb70c86d Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 21:33:57 +0200 Subject: [PATCH 05/20] Trying to fetch payload --- dist/index.js | 4 +++- src/handlers/pushHandler.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index e9741a2..911f3c4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36426,10 +36426,12 @@ module.exports = ({ webhookUrl }) => { // return Promise.resolve() // } + const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload + const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) - return client.send('Hello').then(result => { + return client.send(JSON.stringify({commits, default_branch, language, login, repos_url})).then(result => { client.destroy() return '' }).catch(error => { diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index ad9ed78..6e49bc0 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -11,10 +11,12 @@ module.exports = ({ webhookUrl }) => { // return Promise.resolve() // } + const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload + const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) - return client.send('Hello').then(result => { + return client.send(JSON.stringify({commits, default_branch, language, login, repos_url})).then(result => { client.destroy() return '' }).catch(error => { From e5ce35e1a552d4bee9a191fe3aa9fb60347b2d97 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 21:56:12 +0200 Subject: [PATCH 06/20] Created custom message for push events --- dist/index.js | 22 ++++++++++++++-------- src/handlers/pushHandler.js | 22 ++++++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index 911f3c4..799f812 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36427,11 +36427,12 @@ module.exports = ({ webhookUrl }) => { // } const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload + const data = {commits, default_branch, language, login, repos_url} const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) - return client.send(JSON.stringify({commits, default_branch, language, login, repos_url})).then(result => { + return client.send(createEmbed(data)).then(result => { client.destroy() return '' }).catch(error => { @@ -36443,14 +36444,19 @@ module.exports = ({ webhookUrl }) => { } -function createEmbed({ action, name, body, tag, url, draft, prerelease, published, branch }) { +function createEmbed({ commits, default_branch, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) - embed.setColor(prerelease ? 0xf66a0a : 0x28a745) - embed.setTitle(`${prerelease ? 'Pre-release' : 'Release'}: ${tag} ${name} ${draft ? '(Draft)': ''}`) - embed.setURL(url) - embed.setDescription(`${trimBody(body)}`) - embed.setFooter(`Branch: ${branch}`) - embed.setTimestamp(new Date(published)) + let description = 'Writen in: ' + language + '\n' + + 'Following commits were added: \n' + for(let commit of commits){ + description += commit.message + '\n' + } + embed.setColor(login ? 0xf66a0a : 0x28a745) + embed.setTitle(login + ' created pull request') + embed.setURL(repos_url) + embed.setDescription('Writen in: ' + language) + embed.setFooter(`Default branch: ${default_branch}`) + embed.setTimestamp(new Date(commits[commits.length-1].timestamp)) return embed } diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index 6e49bc0..bf45e6b 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -12,11 +12,12 @@ module.exports = ({ webhookUrl }) => { // } const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload + const data = {commits, default_branch, language, login, repos_url} const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) - return client.send(JSON.stringify({commits, default_branch, language, login, repos_url})).then(result => { + return client.send(createEmbed(data)).then(result => { client.destroy() return '' }).catch(error => { @@ -28,14 +29,19 @@ module.exports = ({ webhookUrl }) => { } -function createEmbed({ action, name, body, tag, url, draft, prerelease, published, branch }) { +function createEmbed({ commits, default_branch, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) - embed.setColor(prerelease ? 0xf66a0a : 0x28a745) - embed.setTitle(`${prerelease ? 'Pre-release' : 'Release'}: ${tag} ${name} ${draft ? '(Draft)': ''}`) - embed.setURL(url) - embed.setDescription(`${trimBody(body)}`) - embed.setFooter(`Branch: ${branch}`) - embed.setTimestamp(new Date(published)) + let description = 'Writen in: ' + language + '\n' + + 'Following commits were added: \n' + for(let commit of commits){ + description += commit.message + '\n' + } + embed.setColor(login ? 0xf66a0a : 0x28a745) + embed.setTitle(login + ' created pull request') + embed.setURL(repos_url) + embed.setDescription('Writen in: ' + language) + embed.setFooter(`Default branch: ${default_branch}`) + embed.setTimestamp(new Date(commits[commits.length-1].timestamp)) return embed } From 2622787d4304e4b33175ef8e7ce1167a49ea83e5 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 21:58:53 +0200 Subject: [PATCH 07/20] Changed the message --- dist/index.js | 4 ++-- src/handlers/pushHandler.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 799f812..a8f7048 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36452,9 +36452,9 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { description += commit.message + '\n' } embed.setColor(login ? 0xf66a0a : 0x28a745) - embed.setTitle(login + ' created pull request') + embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) - embed.setDescription('Writen in: ' + language) + embed.setDescription(description) embed.setFooter(`Default branch: ${default_branch}`) embed.setTimestamp(new Date(commits[commits.length-1].timestamp)) return embed diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index bf45e6b..e32529e 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -37,9 +37,9 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { description += commit.message + '\n' } embed.setColor(login ? 0xf66a0a : 0x28a745) - embed.setTitle(login + ' created pull request') + embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) - embed.setDescription('Writen in: ' + language) + embed.setDescription(description) embed.setFooter(`Default branch: ${default_branch}`) embed.setTimestamp(new Date(commits[commits.length-1].timestamp)) return embed From 197efa23587037e3c1b33f54d444f43128bc80e4 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 22:01:09 +0200 Subject: [PATCH 08/20] Commit --- src/handlers/pushHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index e32529e..82778fa 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -36,7 +36,7 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { for(let commit of commits){ description += commit.message + '\n' } - embed.setColor(login ? 0xf66a0a : 0x28a745) + embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) embed.setDescription(description) From e8298e4ad731a5cd9e34ebb13f227ca50bb48487 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 22:03:34 +0200 Subject: [PATCH 09/20] Minor changes --- src/handlers/pushHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index 82778fa..2141c58 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -34,7 +34,7 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { let description = 'Writen in: ' + language + '\n' + 'Following commits were added: \n' for(let commit of commits){ - description += commit.message + '\n' + description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' } embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') From 0c14ae9c292043b652c1d6bd4bf772cfd04919c2 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 22:03:56 +0200 Subject: [PATCH 10/20] Built the project --- dist/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index a8f7048..1ec1a1b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36449,9 +36449,9 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { let description = 'Writen in: ' + language + '\n' + 'Following commits were added: \n' for(let commit of commits){ - description += commit.message + '\n' + description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' } - embed.setColor(login ? 0xf66a0a : 0x28a745) + embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) embed.setDescription(description) From c841aad8089e340472e2a4306fd61fbd3b6432d6 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 23:47:19 +0200 Subject: [PATCH 11/20] Another commit comming --- src/handlers/pushHandler.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index 2141c58..bacc0ba 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -6,10 +6,10 @@ const { extractDataFromWebhookUrl } = require('../helpers') module.exports = ({ webhookUrl }) => { const { payload, eventName } = github.context - // if (eventName !== 'push') { - // console.warn('push handler can be executed only on "push" action triggers') - // return Promise.resolve() - // } + if (eventName !== 'push') { + console.warn('push handler can be executed only on "push" action triggers') + return Promise.resolve() + } const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload const data = {commits, default_branch, language, login, repos_url} @@ -24,18 +24,12 @@ module.exports = ({ webhookUrl }) => { client.destroy() throw error }) - console.log(JSON.stringify(payload), eventName) - return Promise.resolve() } function createEmbed({ commits, default_branch, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) - let description = 'Writen in: ' + language + '\n' - + 'Following commits were added: \n' - for(let commit of commits){ - description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' - } + let description = createDescription(commits, language, id, message) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) @@ -45,7 +39,11 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { return embed } -function trimBody(body = '') { - if (body.length < 2000) return body - return `${body.substring(0, 2000)}...` +function createDescription(commits, language, id, message) { + let description = 'Writen in: ' + language + '\n' + + 'Following commits were added: \n' + for(let commit of commits){ + description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' + } + return description } \ No newline at end of file From 60650b52839ce795964c3bce2a52359631470fb6 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 23:48:31 +0200 Subject: [PATCH 12/20] Created helper method --- dist/index.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1ec1a1b..5751b1a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36421,10 +36421,10 @@ const { extractDataFromWebhookUrl } = __webpack_require__(8505) module.exports = ({ webhookUrl }) => { const { payload, eventName } = github.context - // if (eventName !== 'push') { - // console.warn('push handler can be executed only on "push" action triggers') - // return Promise.resolve() - // } + if (eventName !== 'push') { + console.warn('push handler can be executed only on "push" action triggers') + return Promise.resolve() + } const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload const data = {commits, default_branch, language, login, repos_url} @@ -36439,18 +36439,12 @@ module.exports = ({ webhookUrl }) => { client.destroy() throw error }) - console.log(JSON.stringify(payload), eventName) - return Promise.resolve() } function createEmbed({ commits, default_branch, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) - let description = 'Writen in: ' + language + '\n' - + 'Following commits were added: \n' - for(let commit of commits){ - description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' - } + let description = createDescription(commits, language, id, message) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) @@ -36460,9 +36454,13 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { return embed } -function trimBody(body = '') { - if (body.length < 2000) return body - return `${body.substring(0, 2000)}...` +function createDescription(commits, language, id, message) { + let description = 'Writen in: ' + language + '\n' + + 'Following commits were added: \n' + for(let commit of commits){ + description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' + } + return description } /***/ }), From bbd44191770ab52a1592c3d00c5777b7520baf26 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 23:52:08 +0200 Subject: [PATCH 13/20] Commit before build --- src/handlers/pushHandler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index bacc0ba..d3f0f44 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -29,7 +29,7 @@ module.exports = ({ webhookUrl }) => { function createEmbed({ commits, default_branch, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) - let description = createDescription(commits, language, id, message) + let description = createDescription(commits, language) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) @@ -39,7 +39,8 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { return embed } -function createDescription(commits, language, id, message) { + +function createDescription(commits, language) { let description = 'Writen in: ' + language + '\n' + 'Following commits were added: \n' for(let commit of commits){ From a700b1278668cf472534aca5347ce467e55bdb4e Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 23:52:36 +0200 Subject: [PATCH 14/20] Test one two --- dist/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5751b1a..b191adb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36444,7 +36444,7 @@ module.exports = ({ webhookUrl }) => { function createEmbed({ commits, default_branch, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) - let description = createDescription(commits, language, id, message) + let description = createDescription(commits, language) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) @@ -36454,7 +36454,8 @@ function createEmbed({ commits, default_branch, language, login, repos_url}) { return embed } -function createDescription(commits, language, id, message) { + +function createDescription(commits, language) { let description = 'Writen in: ' + language + '\n' + 'Following commits were added: \n' for(let commit of commits){ From 9940a0a61af801c484634dafb5877f0e78980c96 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 23:57:25 +0200 Subject: [PATCH 15/20] Removed unused property --- src/handlers/pushHandler.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index d3f0f44..61565c3 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -11,8 +11,8 @@ module.exports = ({ webhookUrl }) => { return Promise.resolve() } - const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload - const data = {commits, default_branch, language, login, repos_url} + const {commits, repository: {language}, sender: {login, repos_url}} = payload + const data = {commits, language, login, repos_url} const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) @@ -27,14 +27,14 @@ module.exports = ({ webhookUrl }) => { } -function createEmbed({ commits, default_branch, language, login, repos_url}) { +function createEmbed({ commits, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) let description = createDescription(commits, language) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) embed.setDescription(description) - embed.setFooter(`Default branch: ${default_branch}`) + embed.setFooter(`Number of commits: ${commits.length}`) embed.setTimestamp(new Date(commits[commits.length-1].timestamp)) return embed } From 9afb73c605ba65e2d562f2888f2dd39a2b03e68c Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Wed, 14 Oct 2020 23:58:32 +0200 Subject: [PATCH 16/20] Build --- dist/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index b191adb..2d3c704 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36426,8 +36426,8 @@ module.exports = ({ webhookUrl }) => { return Promise.resolve() } - const {commits, repository: {default_branch, language}, sender: {login, repos_url}} = payload - const data = {commits, default_branch, language, login, repos_url} + const {commits, repository: {language}, sender: {login, repos_url}} = payload + const data = {commits, language, login, repos_url} const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) @@ -36442,14 +36442,14 @@ module.exports = ({ webhookUrl }) => { } -function createEmbed({ commits, default_branch, language, login, repos_url}) { +function createEmbed({ commits, language, login, repos_url}) { let embed = new MessageEmbed({ type: 'rich' }) let description = createDescription(commits, language) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') embed.setURL(repos_url) embed.setDescription(description) - embed.setFooter(`Default branch: ${default_branch}`) + embed.setFooter(`Number of commits: ${commits.length}`) embed.setTimestamp(new Date(commits[commits.length-1].timestamp)) return embed } From 445c7104b590ab476cd3a2203dcace4fb67865f7 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Thu, 15 Oct 2020 00:02:26 +0200 Subject: [PATCH 17/20] Minor refactor --- dist/index.js | 2 +- src/handlers/pushHandler.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2d3c704..e603efb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36459,7 +36459,7 @@ function createDescription(commits, language) { let description = 'Writen in: ' + language + '\n' + 'Following commits were added: \n' for(let commit of commits){ - description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' + description += `\`${commit.id.substring(0, 6)}\` - ` + `**${commit.message}**` + '\n' } return description } diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index 61565c3..2732f4d 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -44,7 +44,7 @@ function createDescription(commits, language) { let description = 'Writen in: ' + language + '\n' + 'Following commits were added: \n' for(let commit of commits){ - description += `\`${commit.id.substring(0, 6)}\` - ` + commit.message + '\n' + description += `\`${commit.id.substring(0, 6)}\` - ` + `**${commit.message}**` + '\n' } return description } \ No newline at end of file From a053d940cb86eafcfd18a8064a4118a88794a21d Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Thu, 15 Oct 2020 00:10:23 +0200 Subject: [PATCH 18/20] Removed test.yml. Extended the readme file --- .github/workflows/test.yml | 14 -------------- README.md | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 15 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index f189fc6..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Discord Webhook Messages -on: - push: - branches: ['master'] -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Run Discord Webhook - uses: filipkule/discord-webhook-messages@master - with: - webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} - handler: 'push' diff --git a/README.md b/README.md index 22a4df2..1c256e1 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The goal of this action is to produce helpful messages on your Discord server ba - [x] Release - [ ] Pull Request -- [ ] Push (branches / tags) +- [x] Push (branches / tags) - [ ] Page build ## Getting Started: @@ -21,8 +21,10 @@ The webhook URL to use. This should be in a repository secret and the secret sho #### `handler` Handler defines background logic of the action. Currently avaiable handlers: - `release`: Publishes message to your discord server when release is created. + - `push`: Publishes message to your discord server when push action occurs. --- ### Example +#### Release Handler ```yaml name: Discord Webhook Messages on: @@ -39,6 +41,24 @@ jobs: webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} handler: 'release' ``` +#### Push Handler +```yaml +name: Discord Webhook Messages +on: + push: + branches: + - '*' +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run Discord Webhook + uses: bythope/discord-webhook-messages@v1.0.0 + with: + webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} + handler: 'push' +``` ## Contributing From 2756009447738a5d022ba7319c6fc8c8240100a1 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Thu, 15 Oct 2020 00:14:04 +0200 Subject: [PATCH 19/20] Commit before build --- src/handlers/pushHandler.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/handlers/pushHandler.js b/src/handlers/pushHandler.js index 2732f4d..b3ec6ab 100644 --- a/src/handlers/pushHandler.js +++ b/src/handlers/pushHandler.js @@ -11,8 +11,8 @@ module.exports = ({ webhookUrl }) => { return Promise.resolve() } - const {commits, repository: {language}, sender: {login, repos_url}} = payload - const data = {commits, language, login, repos_url} + const {commits, repository: {language}, sender: {login}} = payload + const data = {commits, language, login} const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) @@ -27,12 +27,11 @@ module.exports = ({ webhookUrl }) => { } -function createEmbed({ commits, language, login, repos_url}) { +function createEmbed({ commits, language, login}) { let embed = new MessageEmbed({ type: 'rich' }) let description = createDescription(commits, language) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') - embed.setURL(repos_url) embed.setDescription(description) embed.setFooter(`Number of commits: ${commits.length}`) embed.setTimestamp(new Date(commits[commits.length-1].timestamp)) From 172d8c9898c69bd49d01cbd25864f3d2b176ff00 Mon Sep 17 00:00:00 2001 From: Filip Kulevski Date: Thu, 15 Oct 2020 00:14:35 +0200 Subject: [PATCH 20/20] Build --- dist/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index e603efb..90e82c6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36426,8 +36426,8 @@ module.exports = ({ webhookUrl }) => { return Promise.resolve() } - const {commits, repository: {language}, sender: {login, repos_url}} = payload - const data = {commits, language, login, repos_url} + const {commits, repository: {language}, sender: {login}} = payload + const data = {commits, language, login} const { id, token } = extractDataFromWebhookUrl(webhookUrl) const client = new WebhookClient(id, token) @@ -36442,12 +36442,11 @@ module.exports = ({ webhookUrl }) => { } -function createEmbed({ commits, language, login, repos_url}) { +function createEmbed({ commits, language, login}) { let embed = new MessageEmbed({ type: 'rich' }) let description = createDescription(commits, language) embed.setColor(0x32ecab) embed.setTitle(login + ' pushed some changes') - embed.setURL(repos_url) embed.setDescription(description) embed.setFooter(`Number of commits: ${commits.length}`) embed.setTimestamp(new Date(commits[commits.length-1].timestamp))