From 510fd6227c3cfc886bf2f64259a41311aca4e38c Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 5 Nov 2017 13:37:35 -0500 Subject: [PATCH] Added buildCanary.js function. --- env.json | 4 ++++ src/commands/buildCanary.js | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/commands/buildCanary.js diff --git a/env.json b/env.json index d118d18..9bbf41c 100644 --- a/env.json +++ b/env.json @@ -15,5 +15,9 @@ }, "DISCORD_LOGIN_TOKEN": { "description": "The login token of the bot." + }, + "CANARY_WEBHOOK_URL": { + "required": false, + "description": "The URL for the webhook to trigger canary builds." } } \ No newline at end of file diff --git a/src/commands/buildCanary.js b/src/commands/buildCanary.js new file mode 100644 index 0000000..fa36620 --- /dev/null +++ b/src/commands/buildCanary.js @@ -0,0 +1,24 @@ +const request = require('request'); +const logger = require('../logging.js'); + +exports.roles = ['Admins', 'Moderators']; +exports.command = function (message) { + // Read the URL endpoint from config. + var webhookUrl = process.env.CANARY_WEBHOOK_URL; + if (!webhookUrl) { + message.channel.sendMessage('Failed to start the canary build due to a missing Webhook URL.'); + return; + } + + // Send a POST request to the URL endpoint to trigger the build. + request.post({ url: webhookUrl, json: true, body: { + "ref": "refs/heads/master" + }}, function (error, response, body) { + if (!error && response.statusCode == 200) { + message.channel.sendMessage(`Canary build has been started.`); + } else { + logger.error(error); + message.channel.sendMessage(`Failed to start the canary build due to an error.`); + } + }); +};