hubot-deployment/deployment.coffee

53 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2016-01-21 13:52:05 +01:00
# Description:
# Deployment script
#
# Commands:
# hubot deploy <project> [from branch <branch>] to <environnement> [after <command>[, <command>, ...]]
#
# URLS:
#
# Notes:
#
module.exports = (robot) ->
2016-01-21 15:15:45 +01:00
fs = require 'fs'
robot.hear /deploy +([^\s]+)( +from +branch +([^\s]+))? +to +([^\s]+)( +after (.*))?$/i, (res) ->
2016-01-21 13:52:05 +01:00
project = res.match[1]
environnement = res.match[4]
branch = if res.match[3] then res.match[3] else null
2016-01-21 15:15:45 +01:00
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
2016-01-21 13:52:05 +01:00
cleanCommands = (commands) ->
results = []
2016-01-21 15:15:45 +01:00
commands = commands.map Function.prototype.call, String.prototype.trim
interpreters = {
"sf" : "php symfony",
"sf2" : "php app/console",
"sf3" : "php bin/console",
"artisan": "php artisan",
}
2016-01-21 13:52:05 +01:00
for command in commands
2016-01-21 15:15:45 +01:00
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
2016-01-21 13:52:05 +01:00
results