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.json
to 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.py
to include Slack Incoming Webhook and GoCD dashboard URLs (template) -
Edit
config.py
to defineCI_STAGES
andDEPLOY_STAGES
in 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.json
from Step 1 into thecfg
folder -
cd
into thegocd2gmail2slack
directory (which containsintegrations.py
) -
(optional) To run tests, run
python -m unittest
from 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.json
for subsequent runs -
The script will query all the
'UNREAD'
emails and process them accordingly -
Schedule the running of
python integrations.py
every X minutes using Task Scheduler or Cron