Project versionning detection
This commit is contained in:
parent
f6e605694f
commit
8484ecc662
|
@ -2,7 +2,7 @@
|
||||||
# Deployment script
|
# Deployment script
|
||||||
#
|
#
|
||||||
# Commands:
|
# 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:
|
# URLS:
|
||||||
#
|
#
|
||||||
|
@ -12,11 +12,12 @@
|
||||||
module.exports = (robot) ->
|
module.exports = (robot) ->
|
||||||
fs = require 'fs'
|
fs = require 'fs'
|
||||||
|
|
||||||
robot.hear /deploy +([^\s]+)( +from +branch +([^\s]+))? +to +([^\s]+)( +after (.*))?$/i, (res) ->
|
robot.hear /deploy +([^\s]+)( +with +([^\s]+))?( +from +branch +([^\s]+))? +to +([^\s]+)( +after (.*))?$/i, (res) ->
|
||||||
project = res.match[1]
|
project = res.match[1]
|
||||||
environnement = res.match[4]
|
target = res.match[6]
|
||||||
branch = if res.match[3] then res.match[3] else null
|
program = if res.match[3] then res.match[3] else null
|
||||||
commands = if res.match[6] then cleanCommands res.match[6].split "," else []
|
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
|
directory = "/home/simon/www/repo/" + project
|
||||||
|
|
||||||
|
@ -26,9 +27,47 @@ module.exports = (robot) ->
|
||||||
return res.reply "Project not found [" + directory + "]"
|
return res.reply "Project not found [" + directory + "]"
|
||||||
|
|
||||||
process.chdir(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
|
catch e
|
||||||
res.reply "Exception: " + 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) ->
|
cleanCommands = (commands) ->
|
||||||
results = []
|
results = []
|
||||||
commands = commands.map Function.prototype.call, String.prototype.trim
|
commands = commands.map Function.prototype.call, String.prototype.trim
|
||||||
|
|
Loading…
Reference in a new issue