2015-04-27 16:59:31 +02:00
|
|
|
# Description:
|
|
|
|
# abilità di asjon di usare la shell *nix
|
|
|
|
#
|
|
|
|
# Requires:
|
|
|
|
# None
|
|
|
|
#
|
|
|
|
# Commands:
|
|
|
|
# asjon run/esegui/shell git/npm args...
|
|
|
|
#
|
|
|
|
# Author:
|
|
|
|
# Enrico Fasoli (fazo96)
|
|
|
|
|
|
|
|
cp = require 'child_process'
|
|
|
|
|
|
|
|
nope = ['BZBZ 400-BAD-REQUEST', 'BZBZ DOES-NOT-COMPUTE', 'BZBZ ADMIN-NOT-DETECTED', 'BZBZ IS-NOT-AUTHORIZED', 'BZBZ ACCESS-DENIED']
|
|
|
|
|
|
|
|
isFromAdmin = (res) ->
|
2015-04-27 17:29:58 +02:00
|
|
|
res.message.user.room is process.env.ADMIN_ROOM?.replace(':','#') or res.robot.adapterName is 'shell'
|
2015-04-27 16:59:31 +02:00
|
|
|
|
2015-04-27 19:21:18 +02:00
|
|
|
runCmd = (cmd,res,cb) ->
|
2015-04-27 19:27:35 +02:00
|
|
|
if res? then res.send 'Operazione in corso: '+cmd
|
2015-04-28 14:07:22 +02:00
|
|
|
if process.env.TESTING_ASJON
|
|
|
|
# Fingi di eseguire l'operazione
|
2015-04-28 14:14:34 +02:00
|
|
|
if res? then res.send 'Operazione "completata": '+cmd
|
2015-04-28 14:07:22 +02:00
|
|
|
else cp.exec cmd, (err,stdout,stderr) ->
|
2015-04-27 19:21:18 +02:00
|
|
|
if res?
|
2015-04-27 16:59:31 +02:00
|
|
|
if err
|
2015-04-28 14:14:34 +02:00
|
|
|
res.send 'Operazione fallita:\n'+stdout+stderr
|
2015-04-27 16:59:31 +02:00
|
|
|
else
|
2015-04-27 19:21:18 +02:00
|
|
|
res.send 'Operazione completata:\n'+stdout
|
|
|
|
if cb? then cb err,stdout,stderr
|
|
|
|
|
|
|
|
module.exports = (robot) ->
|
|
|
|
robot.respond /aggiornati|scarica (?:gli )?aggiornamenti/i, (res) ->
|
2015-04-28 14:07:22 +02:00
|
|
|
if !isFromAdmin(res) then return res.send res.random nope
|
2015-04-28 10:11:01 +02:00
|
|
|
runCmd 'git pull && npm install && npm install --dev', res
|
2015-04-27 19:21:18 +02:00
|
|
|
|
|
|
|
robot.respond /(?:controlla gli )?aggiornamenti/i, (res) ->
|
2015-04-28 14:07:22 +02:00
|
|
|
if !isFromAdmin(res) then return res.send res.random nope
|
2015-04-27 19:21:18 +02:00
|
|
|
runCmd 'git fetch && git status', res
|
|
|
|
|
2015-04-28 14:07:22 +02:00
|
|
|
robot.respond /(?:installa (?:le )?)?dipendenze/i, (res) ->
|
|
|
|
if !isFromAdmin(res) then return res.send res.random nope
|
2015-04-28 10:11:01 +02:00
|
|
|
runCmd 'npm install && npm install --dev', res
|
|
|
|
|
2015-04-28 14:07:22 +02:00
|
|
|
robot.respond /(?:esegui (?:i )?)?test/i, (res) ->
|
|
|
|
if !isFromAdmin(res) then return res.send res.random nope
|
|
|
|
runCmd 'npm test', res
|
|
|
|
|
2015-04-28 10:11:01 +02:00
|
|
|
# Run tests on boot and report to ADMIN
|
|
|
|
if process.env.AUTO_RUN_TESTS and process.env.ADMIN_ROOM
|
|
|
|
dest = room: process.env.ADMIN_ROOM.replace(':','#')
|
|
|
|
robot.send dest, 'Operazione in corso: npm test'
|
|
|
|
runCmd 'npm test', null, (err,stdout,stderr) ->
|
|
|
|
if err
|
|
|
|
robot.send dest, 'ATTENZIONE: TEST FAILURE\n'+stdout+stderr
|
|
|
|
else
|
|
|
|
robot.send dest, 'Test superati con successo:\n'+stdout
|
2015-04-27 19:21:18 +02:00
|
|
|
|
|
|
|
robot.on 'githubhook', (data,params) ->
|
|
|
|
if data.ref is 'refs/heads/master' and process.env.AUTO_KILL_ON_UPDATE
|
2015-04-28 10:11:01 +02:00
|
|
|
runCmd 'git pull && npm install && npm install --dev', null, ->
|
|
|
|
dest = name: params.name, room: params.room.replace(':','#')
|
2015-04-27 19:21:18 +02:00
|
|
|
robot.send dest, 'riavvio in 5 SECONDI'
|
|
|
|
reboot = ->
|
|
|
|
console.log 'AUTO IMPICCAGIONE IN CORSO!'
|
|
|
|
process.exit 0
|
|
|
|
setTimeout reboot, 5000
|
2015-04-27 16:59:31 +02:00
|
|
|
|