From f6e605694f2f75b78cafa8b79e0a4d78b8667934 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 21 Jan 2016 15:15:45 +0100 Subject: [PATCH] Command analyzer --- deployment.coffee | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/deployment.coffee b/deployment.coffee index 1c3f8a1..f656650 100644 --- a/deployment.coffee +++ b/deployment.coffee @@ -10,17 +10,43 @@ # module.exports = (robot) -> - robot.hear /deploy ([^\s]+)( from branch ([^\s]+))? to ([^\s]+)( after (.*))?$/i, (res) -> + fs = require 'fs' + + robot.hear /deploy +([^\s]+)( +from +branch +([^\s]+))? +to +([^\s]+)( +after (.*))?$/i, (res) -> project = res.match[1] environnement = res.match[4] branch = if res.match[3] then res.match[3] else null - commands = if res.match[6] then cleanCommands res.match[6].split(',') else [] + commands = if res.match[6] then cleanCommands res.match[6].split "," else [] + + directory = "/home/simon/www/repo/" + project + + try + fs.stat directory, (err, stats) -> + if err != null or !stats.isDirectory + return res.reply "Project not found [" + directory + "]" + + process.chdir(directory) + catch e + res.reply "Exception: " + e cleanCommands = (commands) -> results = [] - commands = commands.map(Function.prototype.call, String.prototype.trim) + commands = commands.map Function.prototype.call, String.prototype.trim + + interpreters = { + "sf" : "php symfony", + "sf2" : "php app/console", + "sf3" : "php bin/console", + "artisan": "php artisan", + } for command in commands - results.push(command) if command != '' + if command != "" + if command.match /(sf[2-3]?|artisan):.+/ + elements = command.split(":") + interpreter = elements[0] + elements = elements.splice 1 + args = elements.join(":") + results.push interpreters[interpreter] + " " + args results