Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (62 sloc) 2.61 KB
# Description:
# Allows hubot to update itself using git pull and npm update.
# If updates are downloaded you'll need to restart hubot, for example using "hubot die" (restart using a watcher like forever.js).
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot update - Performs a git pull and npm udate.
# hubot pending update - Informs if there are pending updates (hubot needs a restart)
#
# Author:
# benjamine
child_process = require 'child_process'
downloaded_updates = false
module.exports = (robot) ->
robot.respond /pending updates?\??$/i, (msg) ->
if downloaded_updates
msg.send "I have some pending updates, KILL ME PLEASE! (hint: hubot die)"
else
msg.send "I'm up-to-date!"
robot.respond /update( yourself)?$/i, (msg) ->
changes = false
try
msg.send "git pull..."
child_process.exec 'git pull', (error, stdout, stderr) ->
if error
msg.send "git pull failed: " + stderr
else
output = stdout+''
if not /Already up\-to\-date/.test output
msg.send "my source code changed:\n" + output
changes = true
else
msg.send "my source code is up-to-date"
try
msg.send "npm update..."
child_process.exec 'npm update', (error, stdout, stderr) ->
if error
msg.send "npm update failed: " + stderr
else
output = stdout+''
if /node_modules/.test output
msg.send "some dependencies updated:\n" + output
changes = true
else
msg.send "all dependencies are up-to-date"
if changes
downloaded_updates = true
msg.send "I downloaded some updates, KILL ME PLEASE! (hint: hubot die)"
else
if downloaded_updates
msg.send "I have some pending updates, KILL ME PLEASE! (hint: hubot die)"
else
msg.send "I'm up-to-date!"
catch error
msg.send "npm update failed: " + error
catch error
msg.send "git pull failed: " + error
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.