From 38616a1760c616ff5506828fd31f710cfe865a55 Mon Sep 17 00:00:00 2001 From: bogdan-1337 Date: Thu, 8 Jun 2023 20:29:57 +0100 Subject: [PATCH 1/4] add logic for cdapp and coinmachine deployments --- scripts/deployments.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/scripts/deployments.js b/scripts/deployments.js index 08e7920..e3981f0 100644 --- a/scripts/deployments.js +++ b/scripts/deployments.js @@ -239,6 +239,58 @@ module.exports = async function(robot) { msg.send(`Keep an eye on the build here: https://github.com/JoinColony/${repo}/actions. A notification on the outcome will also be sent to the chewie-skunkworks channel.`) }); + robot.hear(/!build (cdapp|coinmachine)-(\w+) ([0-9a-fA-F]*) (dev)?/, async msg => { + if (!isDeployer(msg.message.user.id)) return; + + const appTypeRepoMapping = { + "cdapp": { + "frontend": "colonyCDapp", + "block-ingestor": "block-ingestor" + }, + "coinmachine": { + "frontend": "coinMachine", + "block-ingestor": "block-ingestor-coin-machine", + "contracts": "coinMachine" + } + // Add other mappings as needed + }; + + const app = msg.match[1]; + const type = msg.match[2]; + const commitHash = msg.match[3]; + const isDev = msg.match[4] ? '-dev' : ''; + + // Get the corresponding repository + const appMapping = appTypeRepoMapping[app]; + const repo = appMapping ? appMapping[type] : undefined; + + // If the repo is undefined, send a message and return + if (typeof repo === "undefined") { + msg.reply(`The deployment name "${appMapping}-${type}" is not recognized.`); + return; + } + + const formData = { + 'event_type': `${app}-${type}${isDev}`, + 'client_payload':{ + JOB: `build-${app}-${type}${isDev}-image`, + COMMIT_HASH: commitHash + } + } + + await request({ + method: 'POST', + uri: `https://api.github.com/repos/company/${repo}/dispatches`, + keepAlive: false, + body: JSON.stringify(formData), + headers:{ + "Accept": "application/vnd.github.everest-preview+json", + "Authorization": `token ${process.env.HUBOT_GITHUB_TOKEN}`, + "User-Agent": "company/chewie", + } + }); + }); + async function output(msg, res){ if (res.stdout) { msg.send(`Stdout: From 8e655c7c7b3a63425696e908224165a505a13860 Mon Sep 17 00:00:00 2001 From: bogdan-1337 Date: Thu, 8 Jun 2023 20:33:04 +0100 Subject: [PATCH 2/4] fix msg method name --- scripts/deployments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deployments.js b/scripts/deployments.js index e3981f0..cf6e9a6 100644 --- a/scripts/deployments.js +++ b/scripts/deployments.js @@ -266,7 +266,7 @@ module.exports = async function(robot) { // If the repo is undefined, send a message and return if (typeof repo === "undefined") { - msg.reply(`The deployment name "${appMapping}-${type}" is not recognized.`); + msg.send(`The deployment name "${appMapping}-${type}" is not recognized.`); return; } From 8a3f6af5694a4b3a28c6bcab3e6b23b9a31a254c Mon Sep 17 00:00:00 2001 From: bogdan-1337 Date: Thu, 8 Jun 2023 20:33:52 +0100 Subject: [PATCH 3/4] fix error message --- scripts/deployments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deployments.js b/scripts/deployments.js index cf6e9a6..82787e2 100644 --- a/scripts/deployments.js +++ b/scripts/deployments.js @@ -266,7 +266,7 @@ module.exports = async function(robot) { // If the repo is undefined, send a message and return if (typeof repo === "undefined") { - msg.send(`The deployment name "${appMapping}-${type}" is not recognized.`); + msg.send(`The deployment name "${app}-${type}" is not recognized.`); return; } From b770b7e46087760a7f4f9f08d7f4bb97e120ef4f Mon Sep 17 00:00:00 2001 From: bogdan-1337 Date: Thu, 8 Jun 2023 20:38:54 +0100 Subject: [PATCH 4/4] fix org name and add message from chewie --- scripts/deployments.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/deployments.js b/scripts/deployments.js index 82787e2..5c94527 100644 --- a/scripts/deployments.js +++ b/scripts/deployments.js @@ -280,15 +280,17 @@ module.exports = async function(robot) { await request({ method: 'POST', - uri: `https://api.github.com/repos/company/${repo}/dispatches`, + uri: `https://api.github.com/repos/joinColony/${repo}/dispatches`, keepAlive: false, body: JSON.stringify(formData), headers:{ "Accept": "application/vnd.github.everest-preview+json", "Authorization": `token ${process.env.HUBOT_GITHUB_TOKEN}`, - "User-Agent": "company/chewie", + "User-Agent": "joinColony/chewie", } }); + + msg.send(`Keep an eye on the build here: https://github.com/JoinColony/${repo}/actions. A notification on the outcome will also be sent to the chewie-skunkworks channel.`) }); async function output(msg, res){