This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

adding update hubot script

  • Loading branch information...
beneidel committed Jan 4, 2013
1 parent 604ebcb commit e703fe4dc586cde5e6a2ba8b84ebcbdff3513c92
Showing with 68 additions and 0 deletions.
  1. +68 −0 src/scripts/update.coffee
View
@@ -0,0 +1,68 @@
+# 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
+
+

0 comments on commit e703fe4

Please sign in to comment.