 #   None
 #
 # Configuration:
-#   HUBOT_JIRA_DOMAIN
-#   HUBOT_JIRA_PROTOCOL (optional, format: "http|https"; default is "https")
-#   HUBOT_JIRA_PORT (optional; default is 80)
+#   HUBOT_JIRA_URL (format: "https://jira-domain.com:9090")
 #   HUBOT_JIRA_IGNORECASE (optional; default is "true")
 #   HUBOT_JIRA_USERNAME (optional)
 #   HUBOT_JIRA_PASSWORD (optional)


module.exports = (robot) ->
  cache = []
  jiraDomain = process.env.HUBOT_JIRA_DOMAIN
  jiraProtocol = process.env.HUBOT_JIRA_PROTOCOL || "https"
  jiraPort = process.env.HUBOT_JIRA_PORT || 80
  jiraUrl = "#{jiraProtocol}://#{jiraDomain}:#{jiraPort}"

  if jiraProtocol == 'https'
    http = require 'https'
  else
    http = require 'http'

  jiraUsername = process.env.HUBOT_JIRA_USERNAME
  jiraPassword = process.env.HUBOT_JIRA_PASSWORD
  if jiraUsername != undefined && jiraUsername.length > 0
    auth = "#{jiraUsername}:#{jiraPassword}"


            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})
            robot.http(jiraUrl + "/rest/api/2/issue/" + issue)
              .auth(auth)
              .get() (err, res, body) ->
                try
