The GitHub email API script reads an email from standard in and will do one of two things:
-
If the email is from
[email protected]
then it will change theReply-To
header into[email protected]
and write the result to standard out.This means replies are sent to yourself instead of GitHub which allow us to process them before they go to GitHub.
-
If the email is to
[email protected]
then it will look for lines in the email matching these patterns:/^state:\s*(open|closed)/ /^assignee:\s*(.*)/ /^title:\s*(.+)/ /^labels?:\s*(.*)/
If any are found then it will update the issue (found by looking at the
Message-ID
header) with the corresponding value.In addition to updating the issue, it will resend the email to the original reply-to address after having removed all command lines, assuming the (non-quoted) body of the email is non-empty.
-
Clone this repository to your server:
git clone https://github.com/sorbits/github-email-api.git
-
Install required gems (via bundler):
bundle install
-
curl -u «user» -d '{"scopes":["repo"],"note":"GitHub Email API"}' https://api.github.com/authorizations
-
Create
~/.config/github-email-api
, e.g.:oauth_token: «token» email: "[email protected]" log_file: "~/logs/github-email-api.log"
-
Setup your mail server to run email through
procmail
. -
Add the following to
~/.procmailrc
:# Handle GitHub notification email :0fw * ^From:.*\<notifications@github\.com\> | "/path/to/github-email-api" # Handle replies to a notification (me+…@example.org) :0w * ^To:.*\<me\+(.+)@example\.org\> | "/path/to/github-email-api" # Send an email if the above command failed :0e | (formail -rtI'From: "GitHub Email API" <[email protected]>' \ ; echo "Error processing reply, see log for details.") \ | /usr/sbin/sendmail -oi -t [email protected]
Label names can be prefixed with a minus (-
) to remove them. For consistency an optional plus (+
) prefix is allowed when setting labels. Example:
label: bug
label: +bug
label: -bug
Multiple labels can be specified by separating them with a comma or using multiple label
/labels
lines.
labels: -too-vague, +crash
If you use a label name that doesn’t already exist, it will be created.
-
The
github-email-api
script will not retry incase of errors, e.g. ifapi.github.com
return a500 Internal Server Error
. -
Issues closed via email generally show “you closed this issue…” before the reply (presumably stating the reason) since the reply is added via (GitHub’s own) email API which has a noticeable delay.
-
Setting up the GitHub email API is probably too complex for most users.