Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit ec93e61

Browse files
committed
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.
1 parent f5c8c57 commit ec93e61

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/scripts/redmine.coffee

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Description:
22
# Showing of redmine issue via the REST API
3+
# It also listens for the #nnnn format and provides issue data and link
4+
# Eg. "Hey guys check out #273"
35
#
46
# Dependencies:
57
# None
@@ -8,6 +10,7 @@
810
# HUBOT_REDMINE_SSL
911
# HUBOT_REDMINE_BASE_URL
1012
# HUBOT_REDMINE_TOKEN
13+
# HUBOT_REDMINE_IGNORED_USERS
1114
#
1215
# Commands:
1316
# hubot (redmine|show) me <issue-id> - Show the issue status
@@ -221,6 +224,31 @@ module.exports = (robot) ->
221224

222225
msg.reply _.join "\n"
223226

227+
# Listens to #NNNN and gives ticket info
228+
robot.hear /.*(#(\d+)).*/, (msg) ->
229+
id = msg.match[1].replace /#/, ""
230+
231+
ignoredUsers = process.env.HUBOT_REDMINE_IGNORED_USERS or ""
232+
233+
#Ignore cetain users, like Redmine plugins
234+
if msg.message.user.name in ignoredUsers.split(',')
235+
return
236+
237+
if isNaN(id)
238+
return
239+
240+
params = []
241+
242+
redmine.Issue(id).show params, (err, data, status) ->
243+
unless status == 200
244+
# Issue not found, don't say anything
245+
return false
246+
247+
issue = data.issue
248+
249+
url = "#{redmine.url}/issues/#{id}"
250+
msg.send "#{issue.tracker.name} <a href=\"#{url}\">##{issue.id}</a> (#{issue.project.name}): #{issue.subject} (#{issue.status.name}) [#{issue.priority.name}]"
251+
224252
# simple ghetto fab date formatter this should definitely be replaced, but didn't want to
225253
# introduce dependencies this early
226254
#

0 commit comments

Comments
 (0)