Skip to content

Instantly share code, notes, and snippets.

@jlintz
Created May 29, 2013 21:46
Show Gist options
  • Save jlintz/5674085 to your computer and use it in GitHub Desktop.
Save jlintz/5674085 to your computer and use it in GitHub Desktop.
patch for pagerduty.coffee to remember email addresses properly
--- ./node_modules/hubot-scripts/src/scripts/pagerduty.coffee 2013-04-12 18:05:20.000000000 -0400
+++ ./custom_scripts/pagerduty.coffee 2013-05-28 14:29:25.000000000 -0400
@@ -40,8 +40,13 @@
if missingEnvironmentForApi(msg)
return
- emailNote = if msg.message.user.pagerdutyEmail
- "You've told me your PagerDuty email is #{msg.message.user.pagerdutyEmail}"
+ users = robot.brain.usersForFuzzyName(msg.message.user.name)
+ if users.length is 1
+ user = users[0]
+ pagerdutyEmail = user.pagerdutyEmail
+
+ emailNote = if pagerdutyEmail
+ "You've told me your PagerDuty email is #{pagerdutyEmail}"
else if msg.message.user.email_address
"I'm assuming your PagerDuty email is #{msg.message.user.email_address}. Change it with `hubot pager me as you@yourdomain.com`"
else
@@ -53,8 +58,13 @@
robot.respond /pager(?: me)? as (.*)$/i, (msg) ->
email = msg.match[1]
- msg.message.user.pagerdutyEmail = email
- msg.send "Okay, I'll remember your PagerDuty email is #{email}"
+ users = robot.brain.usersForFuzzyName(msg.message.user.name)
+ if users.length is 1
+ user = users[0]
+ user.pagerdutyEmail = email
+ msg.send "Okay, I'll remember your PagerDuty email is #{email}"
+ else
+ msg.send "Sorry, couldn\'t figure it out. I suck."
# Assumes your Campfire usernames and PagerDuty names are identical
robot.respond /pager( me)? (\d+)/i, (msg) ->
@@ -154,7 +164,12 @@
pagerDutyUserId = (msg, users) ->
- email = msg.message.user.pagerdutyEmail || msg.message.user.email_address
+
+ messageUsers = robot.brain.usersForFuzzyName(msg.message.user.name)
+ if messageUsers.length is 1
+ pagerdutyEmail = messageUsers[0].pagerdutyEmail
+
+ email = pagerdutyEmail || msg.message.user.email_address
unless email
msg.send "Sorry, I can't figure out your email address :( Can you tell me with `#{robot.name} pager me as you@yourdomain.com`?"
return
@nmilford
Copy link

Drama.

Nathan => pager me as user@outbrain.com
Hubot => Okay, I'll remember your PagerDuty email is user@outbrain.com

Nathan => pager me 60
Hubot => Sorry, I couldn't find a PagerDuty user for user@outbrain.com. Double check you have a user, and that I know your PagerDuty email with `Hubot pager me as you@yourdomain.com`

But, the user exists. Problem is somewhere around here, but my unfamiliarity with CoffeeScript might make me misunderstand this:

user = users[email]

unless user
  msg.send "Sorry, I couldn't find a PagerDuty user for #{email}. Double check you have a user, and that I know your PagerDuty email with `#{robot.name} pager me as you@yourdomain.com`"
  return

Is that like a Ruby hash? should user = users[email] be users[pagerdutyEmail]

I'm going to read up on CoffeeScript and see if I can grok the code better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment