How Do You Set Up GitHub Actions to Send Notifications to Slack?

0
25
Asked By TechieStar99 On

I'm trying to figure out how to set up Slack notifications from GitHub Actions at my organization. I found an example that uses the `users.lookupByEmail` method in Slack's API, which seems like it could work if I can get the email address of the `${GITHUB_ACTOR}`. However, when I tested using `gh api /users/$ACTOR`, the email field returned `null`, which makes me think I might be doing something wrong or it could be a permissions issue. I feel like this is a common setup, so I'd love to hear how others manage sending Slack notifications from their GitHub Actions. Any advice would be appreciated!

5 Answers

Answered By CodingChick42 On

Check out the Slack and GitHub documentation about permissions. It mentions that if the email isn’t set to public on GitHub, you'll get `null` for the email field. You’ll also run into issues if a user’s primary email is personal and not their organizational one. For us, we mute direct message bots and channel notifications instead, which makes it less intrusive.

Answered By GitGuru88 On

To bridge Slack and GitHub accounts, we maintain a mapping of GitHub usernames to Slack handles. We use Infrastructure as Code (IaC) with Terraform to inject this mapping into GitHub variables. This way, our Slack notification action can replace the usernames correctly before posting messages.

Answered By DevOpsDude22 On

Have you considered using the GitHub app for Slack? It handles a lot of notifications automatically. Users can subscribe to PRs, and you'll get notifications about commits, PRs, deployments, etc., directly in a channel. Plus, if users log into the GitHub app in Slack, it syncs GitHub usernames to Slack names, making it easier.

Answered By PipelinePro On

Our setup sends notifications through a pub/sub system, which interfaces with different services. It's a bit complex, but it has the flexibility to route messages wherever they're needed in our engineering team.

Answered By BuildMaster101 On

We typically use a generic inbox for pipeline notifications and a fixed Slack webhook for important messages. For notifications aimed at the PR author, I just leave a comment on their PR. That way, GitHub sends them an email as well.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.