Created
December 14, 2013 21:48
-
-
Save empiricalthought/7965330 to your computer and use it in GitHub Desktop.
This Applescript can be applied as a rule to incoming GitHub pull request notification e-mails. It will create a reminder in the OS X "Reminders" app if the assignee matches the account on the incoming mail.
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
using terms from application "Mail" | |
on perform mail action with messages theMessages for rule theRule | |
set credentials to do shell script "security find-internet-password -g -s github.com 2>&1 | awk ' | |
/^password:/ { | |
sub(\".*password: \\\"\", \"\") | |
sub(\"\\\".*\", \"\") | |
password = $0 | |
} | |
/acct/ { | |
sub(\".*=\\\"\", \"\") | |
sub(\"\\\".*\", \"\") | |
account = $0 | |
} | |
END { | |
print account \":\" password | |
} | |
'" | |
tell application "Mail" | |
repeat with eachMessage in theMessages | |
set accountName to the content of header named "X-Github-Recipient" of eachMessage | |
set messageID to the content of header named "Message-ID" of eachMessage | |
set thePRName to the subject of eachMessage | |
set thePRPath to do shell script "echo " & quoted form of messageID & " | sed 's/<//;s/@github.com>//;s/pull/pulls/'" | |
set thePRURL to "https://api.github.com/repos/" & thePRPath | |
set assignee to do shell script "curl -u " & quoted form of credentials & " " & thePRURL & " | awk '/\\\"assignee\\\"/ { x = 1; next } | |
x == 1 && /login/ { | |
sub(\".*login\\\": \\\"\", \"\") | |
sub(\"\\\".*\", \"\") | |
print $0 | |
exit | |
}'" | |
if assignee is accountName then | |
tell application "Reminders" | |
set newReminder to make new reminder | |
set name of newReminder to thePRName | |
set theURL to do shell script "echo " & quoted form of thePRPath & " | sed 's/pulls/pull/'" | |
set theURL to "https://github.com/" & theURL | |
set body of newReminder to theURL | |
set due date of newReminder to current date | |
end tell | |
end if | |
end repeat | |
end tell | |
end perform mail action with messages | |
end using terms from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Care must be taken to only apply the script to appropriate messages in Mail. My rule looks like: