Command analyzer
This commit is contained in:
parent
bf6c5e6196
commit
f6e605694f
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue