Created
May 29, 2013 21:46
-
-
Save jlintz/5674085 to your computer and use it in GitHub Desktop.
patch for pagerduty.coffee to remember email addresses properly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ./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 [email protected]`" | |
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 [email protected]`?" | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Drama.
But, the user exists. Problem is somewhere around here, but my unfamiliarity with CoffeeScript might make me misunderstand this:
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.