diff --git a/package.json b/package.json index 6f23b99..b74ca3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asjon", - "version": "1.2.0", + "version": "1.3.0", "private": true, "author": "Enrico Fasoli ", "description": "Il miglior amico della 5IA", diff --git a/scripts/github.coffee b/scripts/github.coffee index 866050d..0f87398 100644 --- a/scripts/github.coffee +++ b/scripts/github.coffee @@ -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...' diff --git a/scripts/shell.coffee b/scripts/shell.coffee index 284db57..66f19a9 100644 --- a/scripts/shell.coffee +++ b/scripts/shell.coffee @@ -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