Permalink
Browse files

Merge

  • Loading branch information...
2 parents 5514871 + 7b023da commit be6daa0698fa92eee186a699e1a2dfac8e332271 @tombell tombell committed Jan 10, 2013
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/scripts/jira-issues.coffee
@@ -7,6 +7,8 @@
# Configuration:
# HUBOT_JIRA_DOMAIN
# HUBOT_JIRA_IGNORECASE (optional; default is "true")
+# HUBOT_JIRA_USERNAME (optional)
+# HUBOT_JIRA_PASSWORD (optional)
#
# Commands:
#
@@ -19,7 +21,12 @@ module.exports = (robot) ->
jiraUrl = "https://" + jiraDomain
http = require 'https'
- http.get {host: jiraDomain, path: "/rest/api/2.0.alpha1/project"}, (res) ->
+ jiraUsername = process.env.HUBOT_JIRA_USERNAME
+ jiraPassword = process.env.HUBOT_JIRA_PASSWORD
+ if jiraUsername != undefined && jiraUsername.length > 0
+ auth = "#{jiraUsername}:#{jiraPassword}"
+
+ http.get {host: jiraDomain, auth: auth, path: "/rest/api/2/project"}, (res) ->
data = ''
res.on 'data', (chunk) ->
data += chunk.toString()
@@ -40,16 +47,18 @@ module.exports = (robot) ->
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.0.alpha1/issue/" + issue)
+ msg.http(jiraUrl + "/rest/api/2/issue/" + issue)
+ .auth(auth)
.get() (err, res, body) ->
try
- key = JSON.parse(body).key
- msg.send "[" + key + "] " + JSON.parse(body).fields.summary.value
+ json = JSON.parse(body)
+ key = json.key
+ msg.send "[" + key + "] " + json.fields.summary
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.parse(body).errorMessages[0]
+ msg.send "[*ERROR*] " + json.errorMessages[0]
catch reallyError
msg.send "[*ERROR*] " + reallyError

0 comments on commit be6daa0

Please sign in to comment.