Permalink
Browse files

Added active listening to #NNN issues

Added `hear` command that allows the bot to listen to `#NNNN` issue numbers and prints information about the ticket.
This also adds a ignored users option so that the robot does not respond to other redmine plugins that may talk in the channel.

This was only tested in hipchat environments.
  • Loading branch information...
1 parent f5c8c57 commit ec93e6122a65a67b7c78cb9a6e145720e4d3dd47 @rdohms rdohms committed Mar 8, 2013
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/scripts/redmine.coffee
@@ -1,5 +1,7 @@
# Description:
# Showing of redmine issue via the REST API
+# It also listens for the #nnnn format and provides issue data and link
+# Eg. "Hey guys check out #273"
#
# Dependencies:
# None
@@ -8,6 +10,7 @@
# HUBOT_REDMINE_SSL
# HUBOT_REDMINE_BASE_URL
# HUBOT_REDMINE_TOKEN
+# HUBOT_REDMINE_IGNORED_USERS
#
# Commands:
# hubot (redmine|show) me <issue-id> - Show the issue status
@@ -221,6 +224,31 @@ module.exports = (robot) ->
msg.reply _.join "\n"
+ # Listens to #NNNN and gives ticket info
+ robot.hear /.*(#(\d+)).*/, (msg) ->
+ id = msg.match[1].replace /#/, ""
+
+ ignoredUsers = process.env.HUBOT_REDMINE_IGNORED_USERS or ""
+
+ #Ignore cetain users, like Redmine plugins
+ if msg.message.user.name in ignoredUsers.split(',')
+ return
+
+ if isNaN(id)
+ return
+
+ params = []
+
+ redmine.Issue(id).show params, (err, data, status) ->
+ unless status == 200
+ # Issue not found, don't say anything
+ return false
+
+ issue = data.issue
+
+ url = "#{redmine.url}/issues/#{id}"
+ msg.send "#{issue.tracker.name} <a href=\"#{url}\">##{issue.id}</a> (#{issue.project.name}): #{issue.subject} (#{issue.status.name}) [#{issue.priority.name}]"
+
# simple ghetto fab date formatter this should definitely be replaced, but didn't want to
# introduce dependencies this early
#

0 comments on commit ec93e61

Please sign in to comment.