Project versionning detection

This commit is contained in:
Simon Vieille 2016-01-21 16:07:27 +01:00
parent f6e605694f
commit 8484ecc662

View file

@ -2,7 +2,7 @@
# Deployment script
#
# Commands:
# hubot deploy <project> [from branch <branch>] to <environnement> [after <command>[, <command>, ...]]
# hubot deploy <project> [with <program>] [from branch <branch>] to <target> [after <command>[, <command>, ...]]
#
# URLS:
#
@ -12,11 +12,12 @@
module.exports = (robot) ->
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 []
robot.hear /deploy +([^\s]+)( +with +([^\s]+))?( +from +branch +([^\s]+))? +to +([^\s]+)( +after (.*))?$/i, (res) ->
project = res.match[1]
target = res.match[6]
program = if res.match[3] then res.match[3] else null
branch = if res.match[5] then res.match[5] else null
commands = if res.match[8] then cleanCommands res.match[8].split "," else []
directory = "/home/simon/www/repo/" + project
@ -26,9 +27,47 @@ module.exports = (robot) ->
return res.reply "Project not found [" + directory + "]"
process.chdir(directory)
fs.stat '.svn', (err, stats) ->
if err == null
deploy new SvnProjectVersionning(branch), commands
fs.stat '.git', (err, stats) ->
if err == null
deploy new GitProjectVersionning(branch), commands
catch e
res.reply "Exception: " + e
class ProjectVersionning
constructor: (@branch) ->
getUpdateCommands: () ->
class SvnProjectVersionning extends ProjectVersionning
getUpdateCommands: () ->
['svn up']
class GitProjectVersionning extends ProjectVersionning
getUpdateCommands: () ->
commands = []
if @branch == null
commands.push 'git pull origin $(git rev-parse --abbrev-ref HEAD)'
else
br = @branch.split('/')
if br.length == 1
commands.push 'git checkout ' + br[0]
commands.push 'git pull origin ' + br[0]
else if br.length == 2
commands.push 'git checkout ' + br[1]
commands.push 'git pull ' + br.join(' ')
commands
deploy = (projectVersionning, commands) ->
console.log projectVersionning.getUpdateCommands()
cleanCommands = (commands) ->
results = []
commands = commands.map Function.prototype.call, String.prototype.trim