aggiunto autoupdate e remote management

This commit is contained in:
Enrico Fasoli 2015-04-27 19:21:18 +02:00
parent 2979a9d8b6
commit a3a02def2a
3 changed files with 29 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{
"name": "asjon",
"version": "1.2.0",
"version": "1.3.0",
"private": true,
"author": "Enrico Fasoli <fazius2009@gmail.com>",
"description": "Il miglior amico della 5IA",

View File

@ -14,7 +14,6 @@ GitHubAPI = require 'github'
github = new GitHubAPI version: '3.0.0'
module.exports = (robot) ->
if process.env.AUTO_INFORM_ON_START
r = room: process.env.AUTO_INFORM_ON_START.replace(':','#')
robot.send r, 'asjon avviato e operativo!'
@ -22,17 +21,12 @@ module.exports = (robot) ->
robot.router.post '/hubot/githubhook/:room/:name?', (req, res) ->
res.send 200
dest = name: req.params.name, room: req.params.room.replace(':','#')
robot.emit 'githubhook', req.body, req.params
s = 'Branch '+req.body.ref+' aggiornato!\n'
cm = req.body.commits.map (c) ->
[c.committer.username,c.message].join ' -> '
robot.send dest, s+cm.join('\n')
if process.env.AUTO_KILL_ON_UPDATE
robot.send dest, 'riavvio in 5 SECONDI'
reboot = ->
console.log 'AUTO IMPICCAGIONE IN CORSO!'
process.exit 0
setTimeout reboot, 5000
robot.respond /(?:(?:mostra(?:mi)?|fammi vedere) )?(?:le )?issue(?:s)?/i, (res) ->
msg = state: 'open', user: 'fazo96', repo: 'asjon', sort: 'updated'
res.send 'controllo issues...'

View File

@ -17,13 +17,33 @@ nope = ['BZBZ 400-BAD-REQUEST', 'BZBZ DOES-NOT-COMPUTE', 'BZBZ ADMIN-NOT-DETECTE
isFromAdmin = (res) ->
res.message.user.room is process.env.ADMIN_ROOM?.replace(':','#') or res.robot.adapterName is 'shell'
module.exports = (robot) ->
robot.respond /(?:run|esegui|shell) (git|npm) (.+)/i, (res) ->
q = res.match[1]+' '+res.match[2]
if isFromAdmin res then cp.exec q, (err,stdout,stderr) ->
runCmd = (cmd,res,cb) ->
res.send 'Operazione in corso: '+cmd
cp.exec cmd, (err,stdout,stderr) ->
if res?
if err
res.send 'command failed:\n'+stderr
res.send 'Operazione fallita:\n'+stderr
else
res.send stdout
else res.send res.random nope
res.send 'Operazione completata:\n'+stdout
if cb? then cb err,stdout,stderr
module.exports = (robot) ->
robot.respond /aggiornati|scarica (?:gli )?aggiornamenti/i, (res) ->
runCmd 'git pull && npm install', res
robot.respond /(?:controlla gli )?aggiornamenti/i, (res) ->
runCmd 'git fetch && git status', res
robot.respond /(?:installa (?:le )?)dipendenze/i, (res) ->
runCmd 'npm install', res
robot.on 'githubhook', (data,params) ->
if data.ref is 'refs/heads/master' and process.env.AUTO_KILL_ON_UPDATE
runCmd 'git pull & npm install', null, ->
dest = name: params.name, room: params.room.replace(':','#')
robot.send dest, 'riavvio in 5 SECONDI'
reboot = ->
console.log 'AUTO IMPICCAGIONE IN CORSO!'
process.exit 0
setTimeout reboot, 5000