Skip to content

Slack notifications from GitHub

David Cook edited this page Sep 21, 2023 · 2 revisions

There's a few options and it's not immediately clear which one to use, and where to configure it. So here's a reference:

Sending from GitHub

GitHub Actions

These are configured in a yaml file on the default branch. They can act on certain conditions (eg PR is merged, with label "api changes"). A GitHub action can send a webhook. Here's a handy article, which makes use of the popular action-slack.

However, any GitHub action requires the secret slack webhook URL. You can store the secret securely as a repository secret. But:

They are not passed to workflows that are triggered by a pull request from a fork.

So you can't act on any events arising from a PR, presumably because the PR can potentially alter the yaml configuration.

Luckily, there's another option:

GitHub Webhooks

Webhooks can be configured on the GitHub repository. The conditions are pretty basic, but you can at least filter by event type. Presumably this will work for a PR from a fork.

However, you probably don't want to be notified for every instance of an event, so can you instead add conditions on the Slack side?

Receiving in Slack

Slack has multiple ways of accepting a notification from GitHub:

GitHub's Slack App

https://openfoodnetwork.slack.com/apps/A01BP7R4KNY-github?settings=1 This is super easy to set up, without configuration on the GH side. It allows you to subscribe a channel to certain events (among other features). But without advanced filtering, so it's pretty noisy and not very helpful. We use this for announcing releases in the #global-community channel.

Legacy webhook integration

https://openfoodnetwork.slack.com/apps/A0F7XDUAZ-incoming-webhooks (we currently have webhooks set up with this method)

Custom Webhook App

https://api.slack.com/messaging/webhooks (the newer method)

Workflow with Webhook

(we seem to have required plan but I haven't tested) https://slack.com/intl/en-au/help/articles/360041352714-Create-more-advanced-workflows-using-webhooks

This will probably have the flexibility to filter based on custom conditions (like PR event type, and label name).

Clone this wiki locally