Post GitHub commits to Slack channel.
This sample shows how to automatically post GitHub commits to a Slack channel using an HTTPS Cloud Function.
- Slack Webhooks API: https://api.slack.com/incoming-webhooks
- Firebase SDK: https://firebase.google.com/docs/functions
- GitHub Webhooks: https://developer.github.com/webhooks/creating/
See file functions/index.js for the code.
The dependencies are listed in functions/package.json.
Deploy and test
To test this integration:
- Create a Firebase Project using the Firebase Developer Console
- Enable billing on your project by switching to the Blaze or Flame plan. See pricing for more details. This is required to be able to do requests to non-Google services.
- Configure this sample to use your project using
firebase use --addand select your project.
- Install dependencies locally by running:
cd functions; npm install; cd -
- Add a WebHook to your GitHub repo with the following settings:
- Payload URL:
- Content type:
- Which events would you like to trigger this webhook?
Just the push event.
- Payload URL:
- Add an Incoming Webhook to your Slack channel and take note of the Webhook URL.
- Set the
github.secretGoogle Cloud environment variables to match the email and password of the Gmail account used to send emails. For this use:
firebase functions:config:set slack.webhook_url="https://hooks.slack.com/services/..." github.secret="A_SECRET_YOU_DEFINED_WHEN_SETTING_UP_THE_GITHUB_WEBHOOK"
- Deploy your project using
- Push a commit to your GitHub repo