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

Commit

Permalink
Repair caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
melbit-deanfogarty committed Jan 10, 2014
1 parent 6f2dbf3 commit 39e8f55
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/scripts/jira-issues.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ module.exports = (robot) ->
now = new Date().getTime()
if cache.length > 0
cache.shift() until cache.length is 0 or cache[0].expires >= now

msg.send item.message for item in cache when item.issue is issue

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) ->
Expand All @@ -74,11 +76,12 @@ module.exports = (robot) ->
else
message += ', fixVersion: NONE'

msg.send message

urlRegex = new RegExp(jiraUrl + "[^\\s]*" + key)
if not msg.message.text.match(urlRegex)
msg.send jiraUrl + "/browse/" + key
message += "\n" + jiraUrl + "/browse/" + key

msg.send message
cache.push({issue: issue, expires: now + 120000, message: message})
catch error
try
msg.send "[*ERROR*] " + json.errorMessages[0]
Expand Down

3 comments on commit 39e8f55

@brettporter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of the cache was that it would prevent spamming the channel with the details if you keep talking about it for a couple of minutes, not just prevent it from hitting JIRA. Was what you meant by "repair" to make it work every time but cache the REST call, or was this to fix something else?

Note that this change makes it mandatory to add hubot to HUBOT_JIRA_ISSUES_IGNORE_USERS, otherwise it'll get itself into an infinite loop under some adapters.

@technicalpickles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you create a new issue for this? Commit comments aren't great for tracking resolution of stuff. Also worth noting that we're looking for a maintainer of these jira scripts.

it'll get itself into an infinite loop under some adapters.

Some adapters have options to not receive messages from itself as well.

@brettporter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - I was hoping the comment here would catch the attention of @melbit-deanfogarty to see if it was intentional. I've found and updated #1174 which discussed this behaviour even if not related to this commit.

I'm happy to contribute as time allows, but don't have the bandwidth to be a maintainer.

Please sign in to comment.