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

Commit

Permalink
Added HUBOT_JIRA_IGNORE_USERS parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcpollak committed May 29, 2013
1 parent 474b56a commit 63fb718
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions src/scripts/jira-issues.coffee
@@ -1,6 +1,8 @@
# Description:
# Looks up jira issues when they're mentioned in chat
#
# Will ignore users set in HUBOT_JIRA_IGNORE_USERS (by default, JIRA and GitHub).
#
# Dependencies:
# None
#
Expand All @@ -9,6 +11,7 @@
# HUBOT_JIRA_IGNORECASE (optional; default is "true")
# HUBOT_JIRA_USERNAME (optional)
# HUBOT_JIRA_PASSWORD (optional)
# HUBOT_JIRA_IGNORE_USERS (optional, format: "user1|user2", default is "jira|github")
#
# Commands:
#
Expand All @@ -26,6 +29,10 @@ module.exports = (robot) ->
if jiraUsername != undefined && jiraUsername.length > 0
auth = "#{jiraUsername}:#{jiraPassword}"

jiraIgnoreUsers = process.env.HUBOT_JIRA_ISSUES_IGNORE_USERS
if jiraIgnoreUsers == undefined
jiraIgnoreUsers = "jira|github"

http.get {host: jiraDomain, auth: auth, path: "/rest/api/2/project"}, (res) ->
data = ''
res.on 'data', (chunk) ->
Expand All @@ -40,39 +47,40 @@ module.exports = (robot) ->
jiraPattern += "i"

robot.hear eval(jiraPattern), (msg) ->
for i in msg.match
issue = i.toUpperCase()
now = new Date().getTime()
if cache.length > 0
cache.shift() until cache.length is 0 or cache[0].expires >= now
if cache.length == 0 or (item for item in cache when item.issue is issue).length == 0
cache.push({issue: issue, expires: now + 120000})
msg.http(jiraUrl + "/rest/api/2/issue/" + issue)
.auth(auth)
.get() (err, res, body) ->
try
json = JSON.parse(body)
key = json.key
if not msg.message.user.name.match(new RegExp(jiraIgnoreUsers, "gi"))
for i in msg.match
issue = i.toUpperCase()
now = new Date().getTime()
if cache.length > 0
cache.shift() until cache.length is 0 or cache[0].expires >= now
if cache.length == 0 or (item for item in cache when item.issue is issue).length == 0
cache.push({issue: issue, expires: now + 120000})
msg.http(jiraUrl + "/rest/api/2/issue/" + issue)
.auth(auth)
.get() (err, res, body) ->
try
json = JSON.parse(body)
key = json.key

message = "[" + key + "] " + json.fields.summary
message += '\nStatus: '+json.fields.status.name
if (json.fields.assignee and json.fields.assignee.displayName)
message += ', assigned to ' + json.fields.assignee.displayName
else
message += ', unassigned'
message += ", rep. by "+json.fields.reporter.displayName
if json.fields.fixVersions and json.fields.fixVersions.length > 0
message += ', fixVersion: '+json.fields.fixVersions[0].name
else
message += ', fixVersion: NONE'
message = "[" + key + "] " + json.fields.summary
message += '\nStatus: '+json.fields.status.name
if (json.fields.assignee and json.fields.assignee.displayName)
message += ', assigned to ' + json.fields.assignee.displayName
else
message += ', unassigned'
message += ", rep. by "+json.fields.reporter.displayName
if json.fields.fixVersions and json.fields.fixVersions.length > 0
message += ', fixVersion: '+json.fields.fixVersions[0].name
else
message += ', fixVersion: NONE'

msg.send message
msg.send message

urlRegex = new RegExp(jiraUrl + "[^\\s]*" + key)
if not msg.message.text.match(urlRegex)
msg.send jiraUrl + "/browse/" + key
catch error
try
msg.send "[*ERROR*] " + json.errorMessages[0]
catch reallyError
msg.send "[*ERROR*] " + reallyError
urlRegex = new RegExp(jiraUrl + "[^\\s]*" + key)
if not msg.message.text.match(urlRegex)
msg.send jiraUrl + "/browse/" + key
catch error
try
msg.send "[*ERROR*] " + json.errorMessages[0]
catch reallyError
msg.send "[*ERROR*] " + reallyError

0 comments on commit 63fb718

Please sign in to comment.