I have blogged about the background and motivations for this package:
http://azam-a.github.io/Email-to-Slack-Notifier-Using-Python/
Of course there are more elegant solutions like gmail2slack or gocd-slack-build-notifier, but in cases of permission constraints to the gocd environment and the only available channel is email, then maybe this solution is acceptable. Nevertheless, it was a good learning exercise for me.
-
Turn on Gmail API for a Google Account (instructions Step 1) and get the
client_secret.jsonto register the app -
Clone this repo
-
In activated virtualenv session (or global environment), install required packages from
requirements.txt:pip install -r requirements.txt -
Edit
config.pyto include Slack Incoming Webhook and GoCD dashboard URLs (template) -
Edit
config.pyto defineCI_STAGESandDEPLOY_STAGESin a form of list of string. These definitions are used by sending rule as well as changeset-exclusion logic in slack.py -
Paste the
client_secret.jsonfrom Step 1 into thecfgfolder -
cdinto thegocd2gmail2slackdirectory (which containsintegrations.py) -
(optional) To run tests, run
python -m unittestfrom the same directory as Step 7 -
Create a Gmail label
'SENT_TO_SLACK'at the intended Gmail account -
run
python integrations.py -
The first run will open a browser to authenticate and authorize a Gmail account
-
The credentials will be saved to
cfg/cred/saved_credentials.jsonfor subsequent runs -
The script will query all the
'UNREAD'emails and process them accordingly -
Schedule the running of
python integrations.pyevery X minutes using Task Scheduler or Cron